Continuing with the series “All you need to know about” today with Typescript
First of all, a brief list of pro/cons in my opinion:
- Use Types allows autocomplete and better tooling.
- Type checking allows you to make the code more solid.
- Warn you of common problems in js(types mixes, wrong returns types)
- Easy adaptation of the actual code(you can work with js code or integrate them as is).
- Full integration in Visual Studio Code(if you use it) and great tooling on major editors.
- Create your own Types and apply them to refactoring
- You can start it simple and when the code becomes more complex, you can add more control with Types and interfaces.
- Appropriate errors if you are using es5, es6, etc.
- Minimal changes to adapt your code to es6, es5, etc(and if you use an unsupported feature the compiler warns you).
- If you don't have types for some external library you have to mark everything with Any Type(most features get lost in that mode).
- Sometimes, valid code (but not quite correct solutions) will mark your error and you need to figure out how to solve it.
- Another language to learn.
- Another tool to build your code.
How to install it, and first steps:
Install Node Package Manager (npm)
$ curl http://npmjs.org/install.sh | sh $ npm --version 1.1.70
Install the TypeScript npm package globally in the command line:
$ npm install -g typescript $ npm view typescript version npm http GET https://registry.npmjs.org/typescript npm http 304 https://registry.npmjs.org/typescript 0.8.1-1
Any modern browser: Chrome is used for this tutorial
Any text editor: Sublime Text is used for this tutorial
Syntax highlighting plugin for text editors
Playground to modify code:
Visual Studio Code support:
Another good guide:
Please, feel free to comment or contact us. You can take a look our Brochure too or visit our Works.