简体   繁体   中英

How to use js libraries with typescript?

I need 'react-keydown' module in my project but i cant find typing's for it . How can I use this module in my typescript project?

Typescript need to recognize your JS library as a Typescript. To achieve this you need a ".d.ts" file (react-keydown.d.ts), It's a interface for the JS functions. There's a Github called DefinitelyTyped and they have React there. I don't know if you only want one function or if this can help but here's the link.

DefinitelyTyped/react

Joao mentioned DefinitelyTyped which is where you should start. If you can't find the library there you either need to create your own definition or declare the 3rd party library as any . You won't get any typedefs of course but you will be able to compile and use the library.

declare var ThirdPartyLibrary;
ThirdPartyLibrary.doStuff();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM