Powered by Blogger.

TypeScript–Surprisingly Simple, Extraordinarily Powerful– Part 6


Use TypeScript with Jquery, Knockout and other libraries

TypeScript does not stop at helping us to write JavaScript code, it also has support for all the popular libraries like JQuery, Knockout, and even Angular. Just take a look at https://github.com/borisyankov/DefinitelyTyped and you would find definitely types libraries for almost all the popular ones.

So, if we would want to use any of these libraries in TypeScript you just need to download there corresponding *.d.ts file and include the reference for the same.

As an example, let's add a Jquery.d.ts file in one of our TypeScript files, and then we will have access to all things $, similar will be the case for the knockout, once the definitely typed reference is added we will be able to access knockout properties like ko.observable.


In the above example, we have added a reference to the Jquery file and now not only TypeScript provides us with the IntelliSense for “$” but also provides a way to integrate all these popular libraries and use it with other TypeScript features.

Similarly, we can do the same for other libraries like a knockout, Angular, and use their corresponding functionalities in TypeScript. In knockout, once the library is referenced we can create a variable of type ko.Observable() and use them to contain all the binding for UI.

Up Next: Unit testing in TypeScript

No comments