[英]How to export two modules/namespaces with same name from multiple files in typescript in index.d.ts?
I'm building a new npm package, I have two different typescript files, they contain namespaces and modules with same name 'X' at the end of each file i declare:我正在构建一个新的 npm package,我有两个不同的 typescript 文件,它们在我声明的每个文件的末尾包含名称空间和具有相同名称“X”的模块:
export default X;
I want to import them both into index.d.ts
file and export them so the outer files (the files that import this repository/package) can import and use X
modules and namespaces我想将它们都导入index.d.ts
文件并导出它们,以便外部文件(导入此存储库/包的文件)可以导入和使用X
模块和名称空间
But when I import them both:但是当我同时导入它们时:
import X from "./file1"
import X from "./file2"
I get this error:我收到此错误:
Duplicate identifier 'X'
Is there a way to have the same namespace in two different typescript file and export them to outer packages?有没有办法在两个不同的 typescript 文件中拥有相同的命名空间并将它们导出到外包?
Yes, there is - using aliases.是的,有 - 使用别名。
file1.ts文件1.ts
class A{}
export default A;
file2.ts文件2.ts
class A{}
export default A;
index.ts索引.ts
import { default as firstOne } from './file1';
import { default as secondOne } from './file2';
console.log(firstOne, secondOne);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.