Types in Real Life
How to improve your dev workflow
Sibelius Seraphini
Slide 2
Slide 2 text
Sibelius Seraphini
@sibelius @sseraphini
2
Slide 3
Slide 3 text
- Motivation
- Basics
- Sum types
- Generics
- REST api study case
- React
- Redux
- Utilities
Outline
3
Slide 4
Slide 4 text
Type System in JS
4
Slide 5
Slide 5 text
- Less bugs
- More maintainability
- Type Driven Development
Motivation
5
Slide 6
Slide 6 text
- Better tools support
- Code completion
- Refactor
- Documentation
- Jump to definition
Motivation
6
Slide 7
Slide 7 text
- Types are set of values
- string - 'a' | 'b' | 'c' | ...
- number - 1 | 2 | 3 | ...
- boolean - true | false
- function - string -> boolean | ...
- object - { a: string, b: number } | ...
What are Types?
7
Slide 8
Slide 8 text
Typing a variable
8
Slide 9
Slide 9 text
Typing a function
9
Slide 10
Slide 10 text
Typing an object
10
Slide 11
Slide 11 text
Nominal Typing
11
- C++, Java, Swift
Slide 12
Slide 12 text
Structural Typing
12
- OCaml, Haskell, Elm
Slide 13
Slide 13 text
Typing an array
13
Slide 14
Slide 14 text
Sum/Union Type
14
Slide 15
Slide 15 text
Intersection Type
15
Slide 16
Slide 16 text
- How to type a function that can be
used for any type of array (int[],
string[], number[])?
Generics
16
Slide 17
Slide 17 text
Generics
17
Slide 18
Slide 18 text
18
Optional type
Slide 19
Slide 19 text
- type the input
- api body payload
- headers
- query string
Typing a REST API
19
Slide 20
Slide 20 text
- type the output (response)
- Get a json output of a REST api
- Transform json to types
- https://transform.now.sh/json-to-flo
w-types/
Typing a REST API
20