When youâ€™re getting started with typescript youâ€™re probably going to run into a bunch of warnings and errors. Pay attention to the messages, Iâ€™ve found them to be almostÂ entirelyÂ correct. However you will see errors of the form
The name $ does not exist in the current scope
Why thatâ€™s jQuery, why doesnâ€™t typescript know about jQuery? Well typescript doesnâ€™t know about anything other than whatâ€™s in the current file. It is a dumb as a muffin. A tasty, tasty cranberry orange muffin. Maybe it has thatÂ streuselÂ toping on itâ€¦ sorry, I really like muffins. What can you do to solve this problem? Well thatâ€™s where definition files come into play. Definition files are, in effect, C include files. They define the public interfaces of the libraries youâ€™re trying to use. Libraries like jQuery and d3.js. Libraries like your own libraries.
If youâ€™re referencing your own typescript file then you donâ€™t need to create a declarationÂ file. Typescript can read its own typescript files so there is no need to generate declarationÂ for them unless youâ€™re distributing the declarationÂ to other developers to develop against. To instruct the transcompiler to make use of either an external typescript file or declarationÂ file you can include a reference in your typescript file.
- *You can see here that I pulled in both a declarationÂ file for jQuery and a typescript file I created.
If youâ€™re looking for a declarationÂ file for aÂ publiclyÂ distributed library then there are some great options. You can manually download it from Boris Yankovâ€™s github repo atÂ https://github.com/borisyankov/DefinitelyTyped. Or you can grab a package off nuget. If youâ€™re using node then you can install the typescirpt definition tool fromÂ http://www.tsdpm.com/Â and install packages using.
tsd install node