4 ms·
I might take the opposite stance and ban destructed named imports, preferring default and wildcard imports. import function from 'function'; import *
by seniorsassycat 9y ago
I might take the opposite stance and ban destructed named imports, preferring default and wildcard imports.
import function from 'function';
import * as module from 'module';
Why wildcard imports over named imports?
Wildcards preserve context. `ReactDOM.render` means more than `render`. Using wildcards avoids collisions - lodash, http, https each have a named export `get` [0]. Wildcards still supports tree shaking! Try it in webpack or rollup - only the named exports that you access will be included in the shooken bundle [1].
[0]: Yeah, I know you can import { get as httpsGet }, but why would I want to?
[1]: Unless you treat the binding as an object. `Object.keys(module)` will break tree-shaking.