TypeScript does two things:
- It adds a C#-like type system with interfaces, classes, et cetera.
- It converts new JS features into code compatable with older browsers.
TypeScript has a lot of support in the React community, and is a great tool if your JavaScript must run in Internet Explorer.
Inside of this repo is a folder with an example project that uses TypeScript.
$ cd transpiling/typescript
$ npm installNotice the tsconfig.json file. This the easiest way to tell TypeScript how you want your code converted.
{
"compileOnSave": true,
"compilerOptions": {
"outDir": "./dist",
"target": "ES3",
"module": "CommonJS"
}
}The target is what version of JavaScript the code must work with. Building will create the output files.
$ npx tsctsc looks for a tsconfig.json file to use automatically.
TypeScript's website has is great reference for the new language features and how to integrate with text editors and IDEs.