Suppose I have:
animals.js
import cat from './cat';
import dog from './dog';
import emu from './emu';
import pig from './pig';
import cow from './cow';
export { cat, dog, emu, pig, cow };
In a module that uses animals.js
, how can I import only a couple of needed ones into a keyed object? I'd like to be able to do something like:
my-module.js
import { cat, dog } as housePets from './animals';
// housePets == { cat: theCatModule, dog: theDogModule }
But according to my IDE, this syntax is not correct.
Is there a way to do this? Or is the best way to simply import all of them individually, then construct my own objects afterward?
Expression statement is not assignment or call
. The spaces before and afterfrom
are red squigglied:Expecting newline or semicolon
. And my ESLint parser highlightsas
with:Parsing error: Unexpected token
. – Indorse