Monday, December 5, 2016

Getting Type declarations in TypeScript 2.0

TypeScript has the concept of Type Definition files to provide TypeScript metadata for libraries that are not written in TypeScript. These TypeScripts files are maintained by the community and available at the DefinitelyTyped repo on GitHub. Before TypeScript 2.0 these type definition files were published on NuGet(Microsofts own package manager). As the TypeScript community kept growing and people outside the Microsoft ecosystem started using it, Microsoft decided to switch to npm as the package source for all type definitions.

So starting from TypeScript 2.0 you require no tools apart from npm. Let’s try this!

  • Open a web application in Visual Studio
  • Right click on your project and choose Quick Install Package… from the context menu
    • Note: if you don’t have this option, go install the Package Installer extension first


  • The Quick Install Package window is loaded. Choose NPM from the list of package managers and specify the library for which you want to load type definition files using the @types/<library> syntax.


  • Click on Install. After the NPM package is downloaded and installed, you can find it inside the node_modules folder of your project:


  • To use the library inside your TypeScript files, import the module and you’ll see that Visual Studio will search(and hopefully find) the related type information:


More information at

No comments: