How to import a js library without definition file in typescript file

前端 未结 5 1761
温柔的废话
温柔的废话 2020-12-01 03:23

I want to switch from JavaScript to TypeScript to help with code management as our project gets larger. We utilize, however, lots of libraries as amd Modules, which we do no

5条回答
  •  旧巷少年郎
    2020-12-01 04:07

    Typically if you just want to need a temporary-faster-solution, that could be done by defining a new index.d.ts in the root of the project folder, then make a module name like described inside package.json file

    for example

    // somefile.ts
    import Foo from '@awesome/my-module'
    
    // index.d.ts on @awesome/my-module
    declare module '@awesome/my-module' {
      const bind: any;
      export default bind;
    }
    

提交回复
热议问题