Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript export and rename default

Tags:

typescript

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?

like image 222
lonix Avatar asked Jan 02 '23 08:01

lonix


1 Answers

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.

like image 164
Titian Cernicova-Dragomir Avatar answered Feb 15 '23 18:02

Titian Cernicova-Dragomir