Last active
December 16, 2015 21:59
-
-
Save ksummerlin/5503457 to your computer and use it in GitHub Desktop.
Using third-party libraries in TypeScript with ambient declarations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <reference path="../Scripts/typings/jquery/jquery.d.ts" /> | |
| $('a').click(function () { | |
| alert('clicked'); | |
| }); |
Author
Author
In this last revision, we have included a reference to the jQuery declarations file downloaded from Github/DefinitelyTyped. The full declaration file gives you much better intellisense than just using a simple variable declaration.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revision #2, we have used the declare keyword to define an ambient declaration. This tells the compiler that an external library will define the variable '$'. Using the 'any' type for the variable will tell the compiler to ignore the standard static typing rules for future '$' references.