I have been attempting to get to know this new 'TypeScript' stuff, and I am a bit curious on something.
Can it still work with existing javascript frameworks like jQuery without the need for a definition file with all of those interfaces? I have been attempting to test this out manually, but so far am a little unsure of how far the functionality extends.
by 'work' I am referring to simple functionality, not IDE features like auto-completion.
Most likely you need to download and include the TypeScript declaration file for jQuery— jquery. d. ts —in your project. Then the compiler will resolve the definitions for jquery automatically.
TypeScript. DefinitelyTyped” and install. This will add a jQuery version of Typescript with an extension same as of Typescript files.
The simple answer is yes.
TypeScript is able to interact fully with any existing Javascript library. You only need the definition file if you want tooling in the IDE to make it easier to use.
Also, if you don't include the definition file, the TypeScript compiler might get mad at you for using a variable that hasn't been defined in your code (like $
). To get around that you might have to do something like
declare var $;
That said, I'm not sure why you wouldn't want to use the jQuery definition file. It surely makes it much more pleasant to write jQuery with.
Yes you can. For example just write:
declare var $;
and you can basically use the JQuery framework without having to define anything else. This is also very handy when you are converting your existing libraries / porting code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With