lonix
lonix

Reputation: 20489

TypeScript export and rename default

interface Foo {
  hello(): string;
}

export default Foo;

Suppose I want to rename it to Bar. Then I must do this:

export {Foo as Bar};    // notice there is no `default`

How do I rename and use default at the same time?

Upvotes: 7

Views: 7908

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249466

For default exports the name does not matter. When importing the client code can specify whatever name they want for the import

import BarOrWhatever from './Bar'

The ability to rename exports is there when you want to re-export non-default exports.

Upvotes: 15

Related Questions