TypeScript
https://www.typescriptlang.org/
Notes
Typed superset of JavaScript developed by Microsoft
It compiles to readable JavaScript
The type system disappears during the build step, so there is no runtime penalty
By moving some errors from runtime to compile time, it becomes easier and faster to fix them
Configuring TypeScript
Flags to the
tsccommand
tsc src/index.ts --target ES2017 --module commonjs --watchtsconfig.jsonfile
{
"compilerOptions": {
"jsx": "react", // transform TSX files into JSX
"strict": true, // enable strict features
"module": "commonjs",
"allowJs": true, // check and compile JS
"target": "es2017", // target environment
"outDir": "lib",
"declaration": true, // create *.d.ts files
"sourceMap": true, // create source map for debug
},
"include": ["src"], // input files
}Basics
Functions
Interfaces and Type Aliases
Classes
Converting from JavaScript to TypeScript
Compile project in "loose mode"
start with tests passing
rename all files to
.ts, with implicit anyfix only compile errors (do not change behaviour)
get tests passing again
Explicit Any
start with tests passing
add
"noImplicitAny": truetotsconfig.jsonWhere possible, provide a specific and appropriate type (explicit any otherwise)
get tests passing again
Squash explicit anys, enable strict mode
Enable strict mode in
tsconfig.jsonReplace explicit anys with more appropriate types (incrementally, in small chunks)
Generics
Top and Bottom types
Advanced Types
Resources
Books
TypeScript Deep Dive - Basarat Ali Syed
Courses
TypeScript 3 Fundamentals v2 - Mike North
GitHub Repositories
TypeStat - Converts JavaScript to TypeScript and TypeScript to better TypeScript
Videos
How the TypeScript Compiler Compiles - Orta Therox
Websites
DefinitelyTyped - The repository for high quality TypeScript type definitions
r/typescript - TypeScript subreddit
TypeScript - Official website and docs
Last updated
Was this helpful?