Can TypeScript interact with jQuery without a definition file?

后端 未结 3 1868
广开言路
广开言路 2021-02-05 06:15

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 jQuer

3条回答
  •  失恋的感觉
    2021-02-05 06:47

    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.

提交回复
热议问题