A TypeScript Installation and Source Code

 

Online

For simple code, for example trying out some code samples without dependencies, you can use the online TypeScript playground at https://www.typescriptlang.org/play/.

Local

To install locally, you first need Node.js and npm, the Node Package Manager. You can get them from here https://www.npmjs.com/get-npm. Once you have those, run npm install -g typescript to install the TypeScript compiler.

You can compile a single TypeScript file by passing it as an argument to the TypeScript compiler, like tsc helloworld.ts. TypeScript compiles to JavaScript.

For projects that contain multiple files, a tsconfig.json file is used to configure the compiler. Running tsc with no arguments from a directory with a tsconfig.json file will compile the whole project according to the configuration.

Source Code

The code samples in this book can be found at https://github.com/vladris/programming-with-types/. Each chapter is in its own separate directory and has its own tsconfig.json.

Code was built with version 3.3 of TypeScript, targeting the ES6 standard, with strict settings.

Each sample file is stand-alone, so all types and functions required to run a code sample are inlined within each sample file. Each sample file uses a unique namespace to avoid naming conflicts, since some example present different implementations of the same function or pattern.

DIY