简体   繁体   中英

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:

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

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?

Yes, there is - using aliases.

file1.ts

class A{}
export default A;

file2.ts

class A{}
export default A;

index.ts

import { default as firstOne } from './file1';
import { default as secondOne } from './file2';
console.log(firstOne, secondOne);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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