How Can I Alias a Default Import in Javascript?
Using Es6 Modules, I Know I Can Alias a Named Import: Import { Foo as Bar } from 'My-Module'; and I Know I Can Import a Default Import: Import defaultMember...
Using ES6 modules, I know I can alias a named import:
import { foo as bar } from 'my-module';
And I know I can import a default import:
import defaultMember from 'my-module';
I'd like to alias a default import and I had thought the following would work:
import defaultMember as alias from 'my-module';
But that results in a parsing (syntax) error.
How can I (or can I?) alias a default import?
2 Answers
defaultMember already is an alias - it doesn't need to be the name of the exported function/thing. Just do
import alias from 'my-module';
Alternatively you can do
import {default as alias} from 'my-module';
but that's rather esoteric.
Origins, Solution and Answer:
Background:
A module can export functionality or objects from itself for the use in other modules
The Modules Used for:
- Code reuse
- Separation of functionalities
- Modularity