This chapter gives tips for quickly trying out TypeScript.
The TypeScript Playground is an online editor for TypeScript code. Features include:
The Playground is very useful for quick experiments and demos. It can save both TypeScript code snippets and compiler settings into URLs, which is great for sharing such snippets with others. This is an example of such a URL:
TS Node is a TypeScript version of Node.js. Its use cases are:
TS Node provides a REPL (command line) for TypeScript:
$ ts-node
> const twice = (x: string) => x + x;
> twice('abc')
'abcabc'
> twice(123)
Error TS2345: Argument of type '123' is not assignable
to parameter of type 'string'.
TS Node enables some JavaScript tools to directly execute TypeScript code. It automatically compiles TypeScript code to JavaScript code and passes it on to the tools, without us having to do anything. The following shell command demonstrates how that works with the JavaScript unit test framework Mocha:
mocha --require ts-node/register --ui qunit testfile.ts
Use npx ts-node
to run the REPL without installing it.