I first heard about Typescript from the announcement that Angular 2 will be built with Typescript. And Angular team’s effort on AtScript will be merged into Typescript 1.5+.
To install the definition files, use tsd. The tool is very similar to bower and npm.
Let’s build something fun!
We are ready to start coding! Let’s build a simple chat using Firebase.
Line 1 imports the firebase type definition installed using tsd. If you look into the definition file, you’ll find the definition of Firebase.
When we try to create Firebase instance in Line 13, the Typescript transpiler makes sure firebaseURL is string. Otherwise, it would generate an error.
You may notice that we haven’t specify the type of firebase in Line 9. Turns out the transpiler performs type inference for you. Try the code out in Webstorm, and you’ll get code completion and all the type check goodies.
The code is fairly straight forward as most of the heavy lifting is handled by the Firebase library.
Let me play with it!
To play with it, clone from github and check out the intro tag. Load up index.html file in your Google Chrome browser, open up Developer Tools and voila!
Questions and feedbacks are welcome!
- Gulp tasks are taken from https://github.com/DanWahlin/AngularIn20TypeScript/blob/master/gulpfile.js
- Typescript Introduction — http://www.typescriptlang.org/Handbook