Inspired by Shawn Wildermuths recent post about using Underscore I wanted to write a short post about how using Typescript can help you learn more about that library and others.
First install Typescript itself. It’s a compiler aswell as a Visual Studio plugin that adds intellisense and some nice features for managing the Typescript files to Visual Studio. Also install WebEssentials plugin to be able to handle Typescript easier outside projects made with the Typescript application project template.
Now open your web project, I just created a standard MVC4 one. And then open up the Package Manager Console.
Now check out the nuget packages matching “underscore” by typing underscore and hitting tab:
for the plain library. It will install itself in /scripts.
for the Typescript definitions. It will install itself in /scripts/typings/underscore
Now, add a reference to the underscore definition file, for example by dragging the file from the solution tree to the editor. Or by writing it manually:
/// <reference path="typings/underscore/underscore.d.ts" />
Now you get underscore intellisense:
Cool huh? I learned much I did not know about underscore just by playing around with the code and the syntax this way.
Note: Currently Typescript is at version 0.91, still an Alpha version. Use it at your own risk. Read the discussions and info on the codeplex site for up to date information.