I have a simple TypeScript (ts) which needs a function from a JavaScript file. How can I import that js file into ts file? Do I have to create a ts file for that js file to be able to use it in my ts file?
标签:
typescript
相关问题
- Angular RxJS mergeMap types
- void before promise syntax
- Ignore Typescript errors in Webpack-dev-server
- Angular: ngc or tsc?
- Programmatically navigating : React Router V4+ Typ
相关文章
- Cannot find module 'redux' 怎么解决?
- How to get a Component's own ElementRef for re
- 'Pick' only refers to a type, but is being
- Why does `keyof any` have type of `string | number
- React testing library: Test attribute / prop
- TypeScript - Puppeteer library error: “Cannot find
- How to reference type of self in Typescript interf
- React and typescript with webpack typing issue
Just for the archives,if you add a /// ref for a JavaScript file inside your TS file, the compiler will try to validate all the code in the JS files and throw a huge error list. Try it with jQuery or something like that and you'll see what I mean.
The easiest way is to just
declare
the function you're using:File1.js
File2.ts
If your scenario is more complex (i.e. multiple files referencing File1.js, or there are many functions in File1.js that would clutter up File2.ts), you can make a File1.d.ts file and reference that from File2.ts:
File1.d.ts
File2.ts