Importing JS File into Typescript

前端 未结 2 1281

I\'m looking at moving over to Typescript and currently looking at doing this slowly if possible file by file.

Now the system I currently have is built with Webpack and

2条回答
  •  灰色年华
    2021-02-08 01:39

    Any ideas I have searched quite a lot but I can't really make sense of importing JS files into Typescript.

    For webpack all you need is to declare the require function and do what you are already used to:

    var foo = require('../../../../vendor/src/foo');
    

    The require function type definition is present here : https://github.com/TypeStrong/ts-loader#loading-other-resources-and-code-splitting

    If you want to use foo in a stronger manner... recommend porting it over to .ts as well instead of struggling to build and then maintain a .d.ts file for it.

提交回复
热议问题