声明模块的类型

时间:2020-01-21 19:40:20

标签: javascript node.js typescript

我有三个文件:

//some-class.js
class SomeClass {}
module.exports = SomeClass
//helpers.js
const someFunc = () => {}
module.exports = {someFunc}
//index.js
const SomeClass = require("./src/some-class")
const helpers = require("./src/helpers")
module.exports = {SomeClass, helpers}

我需要为它们描述类型,所以我创建了index.d.ts:

declare module someModule {
 class SomeClass {}
}
export = someModule

但是为helpers声明类型时出现问题,哪种更好的方法呢?

1 个答案:

答案 0 :(得分:0)

使用命名空间修复该问题:

 {
  orders: [
    {
      type: 'some data',
      id: 'some data',
      number: 'some data',
      startAddress: 'some datasome data',
      endAddress: 'some datasome data',
      loadingDate: 'some data',
      status: 0,
      comments: 'some data',
      isBlocked: false,
      isCompleted: false,
      index: 1
    }
  ]
}