Superset of JavaScript with more features than vanilla JS, like Types, Classes, Interfaces. Typescript need to be compiled to JavaScipt. TypeScript is a programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript and adds optional static typing to the language. It is designed for the development of large applications and transpiles to JavaScript.
What is TypeScript?
- A superset of JavaScript created by Microsoft
- Compiles to plain JavaScript code
- Gives us a bunch of extra features
- Includes many ES6 features
The browser can’t natively parse TypeScript files. So it has to be compiled to regular JS.
TypeScript features
- Strong typing
- Object Oriented features
- Compile time errors
- Object Classes
- Modules – export / import
- let / const scoping
- Other ES6 features like arrow functions
TypeScript compiler
- Written in TypeScript
- Compiles .ts files to .js files
- Installed with NPM
- Supports ES6 Syntax
- Used by Angular
Static Type Checking
- Assign variable, parameter and function types
- Completely optional
- Helps find bugs
- More descriptive code
Available Types
- String
- Number
- Boolean
- Array
- Any
- Void
- Null
- Tuple
Arrays
numberArray: number[]; stringArray: string[]; mixedArray: any[]; myTuple: [string, number, boolean];
Date & Time
publishDate?: any;
publishDate: new Date('01/02/2022 08:30:00');