Reputation: 1837
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?
Upvotes: 0
Views: 1549
Reputation: 447
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);
Upvotes: 1