About Book
This book is about how to put javascript on scale with type annotations. The best book to start using Typescript so far.
Notes
Types:
- any: try not to use it
- unknown: just don’t
- boolean
- number
- bigint
- string
- symbol: use it rarely, mostly for string keys in objects or maps.
- Objects: use it for structural typing
- Arrays
- Typles: Tuples are subtypes of array.
- null: universal stuff
- undefined: Variable that has not been assigned a value yet
- void: Function that doesn’t have a return statment
- never: function that never returns
- enums: they are pretty shit https://www.youtube.com/watch?v=0fTdCSH_QEU
Declaring and Invoking Functions
// TODO
Links:
- Try out
immutable
https://www.npmjs.com/package/immutable
Gists
Compiler
Standard compiler:
- Program is parsed into an AST.
- AST is compiled to bytecode.
- Bytecode is evaluated by the runtime.
Typescript:



Type literal: A type that represents a single value and nothing else.
Structural typing: A style of programming where you just care that an object has certain properties, and not what its name is (nominal typing). Also called duck typing in some languages (or, not judging a book by its cover).
Intermission: Type Aliases, Unions, and Intersections
Type aliases
type Age = number type Person = { name: string age: Age }
let age: Age = 55 let driver: Person = { name: 'James May' age: age }
Union and intersection types

type Cat = {name: string, purrs: boolean} type Dog = {name: string, barks: boolean, wags: boolean} type CatOrDogOrBoth = Cat | Dog type CatAndDog = Cat & Dog // Cat let a: CatOrDogOrBoth = { name: 'Bonkers', purrs: true } // Dog a = { name: 'Domino', barks: true, wags: true } // Both a: CatAndDog = { name: 'Donkers', barks: true, purrs: true, wags: true }