
TypeScript Design Patterns
By :

The contents of this chapter are expected to work on all major and up-to-date desktop operating systems, including Windows, OS X, and Linux.
As Node.js is widely used as a runtime for server applications as well as frontend build tools, we are going to make it the main playground of code in this book.
TypeScript compiler, on the other hand, is the tool that compiles TypeScript source files into plain JavaScript. It's available on multiple platforms and runtimes, and in this book we'll be using the Node.js version.
Installing Node.js should be easy enough. But there's something we could do to minimize incompatibility over time and across different environments:
PATH
is properly configured.Open a console (a command prompt or terminal, depending on your operating system) and make sure Node.js as well as the built-in package manager npm
is working:
$ node -v
6.x.x
$ npm -v
3.x.x
TypeScript compiler for Node.js is published as an npm package with command line interface. To install the compiler, we can simply use the npm install
command:
$ npm install typescript -g
Option -g
means a global installation, so that tsc
will be available as a command. Now let's make sure the compiler works:
$ tsc -v Version 2.x.x
You may get a rough list of the options your TypeScript compiler provides with switch -h
. Taking a look into these options may help you discover some useful features.
Before choosing an editor, let's print out the legendary phrase:
test.ts
:function hello(name: string): void { console.log(`hello, ${name}!`); } hello('world');
tsc
: $ tsc test.ts
test.js
. Execute it with Node.js to get the ceremony done:$ node test.js hello, world!
Here we go, on the road to retire your CTO.