Using npm modules in Typescript

后端 未结 3 615
陌清茗
陌清茗 2021-01-02 02:16

I would like to use npm module in Typescript project but there is no typings or tsd for this module. When I try use import Module from \'module\' I had an error

3条回答
  •  渐次进展
    2021-01-02 02:58

    In case you wish not to pollute your imports with requires, you can follow the following method.

    You can create a module.d.ts definition file which contains the following

    declare module Module {}
    

    Your imports should work now.

    If you wish to import something like

    import { abc } from 'module';
    

    just go ahead and add the following to module.d.ts

    declare module Module {
        export let abc: any
    }
    

提交回复
热议问题