TypeScript发布带有嵌套对象类型的模块

我正在使用TypeScript编写软件包。我想通过主软件包文件发布软件包中的几个模块。

例如,我有三个模块core / module1,core / module2和module3。我想以某种方式导出它们,这样就可以访问它们:

import myPackage from 'my-package'; // the package that I created with the three modules

myPackage.core.module1;
myPackage.core.module2;
myPackage.module3;

我已经在主包文件中尝试过此解决方案:

import module1 from './core/module1';
import module2 from './core/module2;
import module3 from './module3';

export = {
    core: {
        module1,module2
    },module3
}

这正常工作,除了模块中的所有类型都将丢失。例如,如果module1导出接口IModule1Interface,则在导入包后将无法再使用此接口。即以下代码将不再起作用,因为找不到接口类型:

import myPackage from 'my-package';

const myInterface: myPackage.IModule1Interface = {};
ether1984 回答:TypeScript发布带有嵌套对象类型的模块

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2676183.html

大家都在问