简体   繁体   English

声明模块类型

[英]Declare types for module

I have three files:我有三个文件:

//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}

I need to describe types for them, so I`ve created index.d.ts:我需要为它们描述类型,所以我创建了 index.d.ts:

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

But problem with declaring types for helpers , what is the better way to do it?但是为helpers声明类型的问题,更好的方法是什么?

Fixed it with namespace:使用命名空间修复它:

declare module someModule {
  class SomeClass {
    constructor(v: string);
    test: (v: string) => void;
  }

  namespace helpers {
    export function someFunction(v: any): Promise<string>;
  }
}

export = logger;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM