In this section, we will see how to use third party libraries like jquery or angular or anything with TypeScript. TypeScript, provides this flexibility to use any third party libraries on the top of your TS file, using some interface. And, this interface is called Definitely Typed in TypeScript. Here, is the URL of Definitely Typed http://definitelytyped.org/. Once you open the same, it will open the following page.
Here, when you click on >_TSD link, you will land on http://definitelytyped.org/tsd/.
Here, when you search for the desired library, it will list the desired file, which you can then download from here and add the same in project.
Similarly, I also need Toastr library as shown below.
Now, let me show the files, which I have included from the portal.
Now, Toastr file has a dependency on Jquery file, hence, In that toastr file, I have added the reference of Jquery at the top as shown below in the screenshot.
After, that I have modified my script as shown below in the snippet.
And, it’s equivalent JS looks like
Now, after including third part library in the TS file, you can get the intellisense of that library as well as shown below in the screenshot.
Apart from this, I have also modified the HTML file to fix the Jquery dependency and other CSS stuffs like shown below.
With the above change in place, it will produce the result
I hope, you would have liked this discussion. Thanks for Joining me. We’ll continue delve further. Till then stay tuned and Happy Coding.
973 total views, 1 views today