Getting Started With TypeScript
Install the TypeScript transpiler using npm:
Then use tsc
to manually compile a TypeScript source file into ES5:
Note About ES6 Examples
Our earlier ES6 class won't compile now. TypeScript is more demanding than ES6 and it expects instance properties to be declared:
Note that now that we've declared toppings
to be an array of strings, TypeScript will enforce this. If we try to assign a number to it, we will get an error at compilation time.
If you want to have a property that can be set to a value of any type, however, you can still do this: just declare its type to be "any":
Last updated