@kadikraman
Formidable
Frontend
Backend
👑
Frontend
Backend
2. reduce production errors
1. communicate intent
const sum = (a, b) => a + b;
sum(2, 6);
const sum = (a, b) => a + b;
sum(2, 6);
// 8
const sum = (a, b) => a + b;
sum(2, "potato");
const sum = (a, b) => a + b;
sum(2, "potato");
// "2potato"
const sum = (a, b) => a + b;
sum(undefined, null);
const sum = (a, b) => a + b;
sum(undefined, null);
// NaN
const sum = (a, b) => a + b;
sum(undefined, null);
// NaN
sum(2, "potato");
// "2potato"
sum(2, 6);
// 8
const addOne = array => array.map(val => val + 1);
addOne([1, 2, 3])
const addOne = array => array.map(val => val + 1);
addOne([1, 2, 3])
// [2, 3, 4]
const addOne = array => array.map(val => val + 1);
addOne({})
const addOne = array => array.map(val => val + 1);
addOne({})
/**
* Adds together two numbers
* @param a (number): first number to add
* @param b (number): second number to add
*/
const sum = (a, b) => a + b;
I could add some comments?
Just kidding - no one reads comments
const sum = (a: number, b: number): number => a + b;
I could add explicit type information?
Types are checked before run-time
Types are checked before run-time
Types are checked at run-time, during execution
Types are checked before run-time
Types are checked at run-time, during execution
JavaScript is a
language
Statically typed language that compiles to JavaScript
Static code analysis
... or something else entirely!
Flow - like eslint, but for types
TypeScript - a statically typed language
"Opt in" by adding a flow declaration at the top of the file
TS is a superset of JS (so any valid JS file is also a valid TS file)
But you should change the file extensions to .ts and .tsx
Slow to recompile on large projects
😱
Usually fast, but notoriously unstable
(Transpiles to OCaml which compiles to JS)
let add = (x: int, y: int) : int => x + y;
✅ static code analysis
✅ statically typed
add : Number -> Number -> Number
add a b =
a + b
(compiles to JS)
✅ static code analysis
✅ statically typed
Reliability in prod
Effort to learn
JavaScript
Reliability in prod
Effort to learn
JavaScript
Flow
Reason
Elm
TypeScript
Reliability in prod
Effort to learn
JavaScript
Flow
Reason
Elm
TypeScript
Reliability in prod
Effort to learn
JavaScript
Flow
Reason
Elm
TypeScript