from "module" import x

Would it be possible to have python style import statements where the module you're importing from comes first? That way, using an IDE you can autocomplete the module's exports.
So, instead of having import {x} from "module" you would have from "module" import {x}.

Right now it is possible to get autocomplete if you go back to the curly braces, but sometimes it's a bit annoying. I know that python allows you to import with both ways, so my question is would there be any reason that javascript can't implement this?

I suspect no, that ship has sailed.

See https://esdiscuss.org/topic/from-foo-import-foo as well.

That's unfortunate. I actually found the link you've posted to be very helpful, the snippet suggestion seems like it would solve the problem. Do you have any idea why syntax we have now was chosen?

I don't know why; hopefully someone can fill in the history.

(Note that even if I'd have preferred from-first syntax, I would be pretty opposed to having two distinct syntax choices for importing)

1 Like

Note that IDE are free to do snippet insertion. Eg, writting "import " inserts:

import [ ] from "[|]";
//                ^ Insertion pointer here
//      ^ Press Tab to jump to this location

That would allow you to write the module path first, then the imports can be auto-completed while you type in the import specifiers.

4 Likes