portability: allow .js in import specifiers
#2066
Labels
Comments
.js in import identifiers..js in import specifiers
|
It seems TS support import |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


It is awkward, but TypeScript officially supports using
.jsin import specifiers, like so:where
./path/to/some/file.jsdoes not actually exist, but the file./path/to/some/file.tsactually exists, and TypeScript will correctly (officially) usefile.ts.In fact, to show how official it is, TypeScript more recently even added the feature that when you auto-import something, if you are already use
.jsextensions in all you import specifiers, the new automatically-added import statement will also have the.jsextension for consistency.But why?
When compiling TypeScript code to JavaScript, we want it to work out of the box in native ES Module systems (like in browsers).
TypeScript team has said they do not (currently at least) wish to modify import specifiers (f.e. converting
.tsto.js), but that they officially support.js.Thus, using the
.jsextensions makes importing in native ES Module systems easier, because browsers do not yet support things likeimport 'some/file': the browser will try to load the equivalent of'current-file-folder/some/file'instead of'current-file-folder/some/file.js'and it will fail, unless.jsextensions after TypeScript compilation.This feature would be compatible with TypeScript, and would allow us to compile to WebAssembly or to plain JavaScript with native ES Modules more easily without the extra workarounds.
Some people will despise the feature, but they don't have to use it. And honestly as an engineer that needs to get things done, it's a perfectly fine solution.
The text was updated successfully, but these errors were encountered: