TypeScript: import external module from node_modules

前端 未结 1 1104
再見小時候
再見小時候 2021-01-18 06:57

There is a npm module one-two-three for example. It contains TS files index.ts (the main) and functions.ts.

functions.ts:

相关标签:
1条回答
  • 2021-01-18 07:17
    /// <reference path="node_modules/one-two-three/index.d.ts" />
    import mo = require("one-two-three");
    

    No reaction.

    It should work.

    A file .d.ts in TypeScript is like a file .h in C. It's normal to use it when a dependency is imported from another project or sub-project.

    If the file your-project/node_modules/one-two-three/index.d.ts isn't written correctly, I suggest to copy it to your-project/one-two-three.d.ts, and then fix the copy. Using the module name as file name makes the /// <reference optional. Just write:

    import mo = require("one-two-three");
    
    0 讨论(0)
提交回复
热议问题