- (TSC) | TypeScript Source Code → TypeScript AST
- (TSC) | AST is checked by Type Checker
- (TSC) | TypeScript AST → JavaScript Source
- (JS Runtime) | JavaScript Source → JavaScript AST
- (JS Runtime) | AST → bytecode
- (JS Runtime) | Bytecode is evaluated by runtime
- Type System: a set of rules that a typechecker uses to assign types to
your program
- Explicit Syntax: it is required to tell the compiler what type everything is
- Inference: Allow the compiler to infer the type of everything automatically
TypeScript is inspired by both.
let a: number = 1; // a is a number
let b: string = 'hello'; // b is a string
let c: boolean[] = [true, false]; // c is an array of booleans
let a = 1; // a is a number
let b = 'hello'; // b is a string
let c = [true, false]; // c is an array of booleans
In general, it is good style to let TypeScript inver as many types as it can
for you, keeping explicitly typed code to a minimum
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"lib": ["es"],
"outDir": "dist",
"sourceMap": true,
"removeComments": false
},
"include": ["src/**/*"]
}