Blog>
Snippets

Importing an entire module as an alias

Demonstrate how to import all the exported components of a module using the wildcard '*' and an alias.
// Assume there is a module named 'exampleModule' with several exported components

import * as Alias from './exampleModule';

// Now you can use any exported member of 'exampleModule' like so:
console.log(Alias.someFunction());
console.log(Alias.someVariable);
This code imports all the exported members of the 'exampleModule' using a wildcard (*) and assigns them to an alias 'Alias'. Then, we can use 'Alias' to access any exported member (function, variable, class, etc.) within the module.