TypeScript
Features
- better development-time tooling
- static code analysis
- compile-time type checking
- code level documentation
Main principle
Three parts
- language
- compiler (transpiler)
- programmer can decide version of the generated code (EMCAScript 3 or newer)
- removes the typing information
- performs static code analysis
- emit warnings/errors
- perform tasks such as combining the generated code into a single file
- language service
- collects type information from the source code and allow dev tools to provide intellisense
Diff with other typed languages
- type equivalence
- Others -> nominal type system - answer this question based on whether x is an instance of a class/type named {whatever type you're looking for}
- require everything to be in classes
- TypeScript is a structural type system - only care about the shape of an object.
- wide to narrower
Basics
Interfaces vs Types
- type alias can handle primitives and is very flexible - string or number
- sort eagerly
- interfaces limited to JS objects and sub types - arrays and functions
- things that have prototype
- can describe ojbect, functions, arrays
- parse like functions - sorted out lazily
Express with Typescript
React with Typescript
- [Typed Action Creators and Reducer]
- [Use Function Component to Define Types]
- [useParams Hook Require Defined Type]
To Review
- function signature overloading
- lexical scope
- index signature - combining types and interfaces