Head first TypeScript
TypeScript is a superset of JavaScript that compiles to plain JavaScript. It is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript adds optional types, classes, and modules to JavaScript.
Microsoft designed TS with specific architectural parameters in mind, which allow TS to integrate fully and easily with existing JS code, while providing robust features external to JS.
- Providing a Type Check
- More Powerful Object-Oriented Programming
- Basic TS Compiler
- TypeScript Standalone Compiler, TSC
- Language Service
- Tool Integration
Getting Started
npm i -g typescript
tsc --version
## create a new tsconfig.json configuration file
tsc --init
## compile a single file
tsc hello.ts
## TS Compiler
tsc hello.ts
tsc --outFile file.js file.ts
tsc @args.txt
tsc --build tsconfig.json
Basic TS Types
- Boolean
- Number
- String
- Array
- Tuple
- Enum
- Any
- Void
- Null and Undefined
- Never
- Object
Union Types
let mathematician = Math.random() > 0.5
? undefined
: "Mark Goldberg";
let thinker: string | null = null;
if (Math.random() > 0.5) {
thinker = "Susanne Langer"; // Ok
}
Kinds of Errors
- Syntax Errors
- Type Errors
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here