I want to have the ability to not have to type a module name (even an alias for a module) in front of all the places I am using a value from that module. (I'd rather not have to e.g. resort to running the C pre processor so I can do #include type stuff.)
(Close but no cigar: Angular 2 import statement wildcard syntax)
I want
import * from "./MyModule";
console.log( foobar );
instead of annoying stuff like:
console.log( MyModule.foobar )
or:
import * as M from "./MyModule";
console.log( M.foobar );
import * from "./MyModule";
is not part of the ES Module specification. You cannot simply inject members into the scope without naming them. Identifier conflicts could arise whenever a module changed.
As @haim770 points out in his comment, this would be very much like the much maligned (and very rightly so) with
statement.
It is simply not allowed.
Typescript wildcard import all module names into current namespace?
It is bad practice why?
Say you have couple hundreds modules in you MyModule and you want to import all think of how many unnecessary modules are going to import which you may will not use and that will take memory and make your app slow, You should import import the only module you want to work with.
e.g
import {A, D} from './MyModules';
If you still want to use wild card which will import all your modules
e.g
import * as http from "http"
then you should also use tree shaking so when deploying your app you can get rid off all other unnecessary modules.
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With