TypeScript is a superset of JavaScript which primarily provides optional static typing, classes and interfaces. One of the big benefits is to enable IDEs to provide a richer environment for spotting common errors as you type the code.
npm install -g typescript
When there’s a variable or an argument in a function or method call, you can annotate your code with types. To annotate, follow the variable or argument with a colon and followed by it’s type.
var myName: string = "Andrew";
function printName(name: string) {
console.log(name);
}Interfaces are great ways to set up agreements on the shape of object literals.
interface Contact {
name: string,
email: string,
phone: string
}
var addressBook: Contact[] = [];TypeScript uses ECMAScript 6 classes and adds a little TypeScript goodness.
interface Point {
x: number,
y: number
}
class Monster {
constructor(public name: string, public initialPosition: Point) {
}
}
var scary = new Monster("Alien", {x: 0, y: 0});- TSLint
- Types auto installer
- TypeScript Hero
- Command: "type", "import"