TypeScript is a typed superset of JavaScript that compiles directly to JavaScript code. TypeScript files commonly use the .ts
extension. Many IDEs support TypeScript without any other setup required, but TypeScript can also be compiled with the TypeScript Node.JS package from the command line.
Visual Studio 2015
includes TypeScript.Visual Studio 2013 Update 2
or later includes TypeScript, or you can download TypeScript for earlier versions.WebStorm 2016.2
comes with TypeScript and a built-in compiler. [Webstorm is not free]IntelliJ IDEA 2016.2
has support for Typescript and a compiler via a plugin maintained by the Jetbrains team. [IntelliJ is not free]Atom
supports TypeScript with the atom-typescript package.Sublime Text
supports TypeScript with the typescript package.You can install TypeScript globally to have access to it from any directory.
npm install -g typescript
or
You can install TypeScript locally and save to package.json to restrict to a directory.
npm install typescript --save-dev
You can install from:
npm install typescript
npm install typescript@beta
npm install typescript@next
The tsc
compilation command comes with typescript
, which can be used to compile code.
tsc my-code.ts
This creates a my-code.js
file.
You can also provide compilation options that travel with your code via a tsconfig.json
file. To start a new TypeScript project, cd
into your project's root directory in a terminal window and run tsc --init
. This command will generate a tsconfig.json
file with minimal configuration options, similar to below.
{ "compilerOptions": { "module": "commonjs", "target": "es5", "noImplicitAny": false, "sourceMap": false, "pretty": true }, "exclude": [ "node_modules" ] }
With a tsconfig.json
file placed at the root of your TypeScript project, you can use the tsc
command to run the compilation.