you can turn on a linter that complains if you default-import something with a different name as it was defined as or even the filename.
a better refactoring will understand when a class/function is imported under the same name that it was defined with and will change both.
a decent autocompletion will of course suggest the default import. that’s the whole point of ES6 import syntax: all of it is statically analyzable. The only problem here is when the exported object isn’t a class or named function, because then the name has to be “magically” derived from the filename.
They’re right about the CommonJS interop, but i hope few people have to write anything else than ES6+ these days. Typos are a problem of course. You don’t want to write a linter for everything like this.
I'd be reluctant to have my linter complain about what names I use for default-imports because sometimes using a different name is the only way to avoid a collision.
8
u/flying-sheep Aug 27 '18
all of this is implementation-specific.
you can turn on a linter that complains if you default-import something with a different name as it was defined as or even the filename.
a better refactoring will understand when a class/function is imported under the same name that it was defined with and will change both.
a decent autocompletion will of course suggest the default import. that’s the whole point of ES6 import syntax: all of it is statically analyzable. The only problem here is when the exported object isn’t a class or named function, because then the name has to be “magically” derived from the filename.
They’re right about the CommonJS interop, but i hope few people have to write anything else than ES6+ these days. Typos are a problem of course. You don’t want to write a linter for everything like this.