You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
importModuleSpecifierEnding = js doesn't apply for autocomplete within import paths #44374
No I don't set that, I can't actually remember why I ended up needing to use .js imports but at some point this not having it was causing exceptions due to some bundling problem. I just tried to remove and it seemed to work, I'm a little hesitant to change it when it working though.
But why would you need allowJS for this to work when I've said I want to use .js imports already with importModuleSpecifierEnding?
Importing a .js file should not be allowed at all if allowJs is not enabled, so files with a .js extension will not show up in the completion list.
That is, if you have allowJs: false (this is the default) and the file
// file: myLib.jsexportconstmyConst=1;
and type the following in a .ts file,
myConst
You should not be offered a completion at all. If you enable allowJs, this should auto complete to the .js file assuming you have "typescript.preferences.importModuleSpecifierEnding": "js".
What I think is a bug, is that we complete with the .ts ending when there is also a .ts file with the same name present. It looks like the importModuleSpecifierEnding setting is just used to decide whether or not we remove the extension on string literal completion in the import. If allowJs is false, the .js import is not found, but we still offer the completion for the .ts file with the same name, but with the extension (incorrectly) attached. I think in this case we should offer the completion without any extension.
Edit: after more investigation I see that auto import completion (not import string completion) adds the .js extension even if allowJs is false, if there is a .ts file present with the same name. I'm no longer sure if it is intended behavior or not to offer import completions with .js with allowJs: false...
I can't remember the exact reason but using .js fixed a compile/bundling issue for me at some point. I use tsc and then webpack on its output, could be related to workers, dynamic imports or es modules.
Auto imports are working correctly and these path completions are working incorrectly. You’re never allowed to write .ts in a module specifier. You are always allowed to write a module specifier for a TS file as a .js path, and you are allowed to write an import for an actual JS source file only if allowJs is enabled. The example shown here is for a TS source file, so the completion should be shown as number.js regardless of the allowJs setting.
Reacted by Daniel Imms, Jesse Trinity and Gabriel Bider
Activity
jessetrinity commentedon Jun 11, 2021
Do you have
?
edit: see https://www.typescriptlang.org/tsconfig#allowJs. We probably need something to indicate that you need to set
allowJsto actually get the.jsimports.Tyriar commentedon Jun 12, 2021
No I don't set that, I can't actually remember why I ended up needing to use .js imports but at some point this not having it was causing exceptions due to some bundling problem. I just tried to remove and it seemed to work, I'm a little hesitant to change it when it working though.
But why would you need
allowJSfor this to work when I've said I want to use .js imports already withimportModuleSpecifierEnding?jessetrinity commentedon Jun 14, 2021
Importing a
.jsfile should not be allowed at all ifallowJsis not enabled, so files with a.jsextension will not show up in the completion list.That is, if you have
allowJs: false(this is the default) and the fileand type the following in a
.tsfile,myConstYou should not be offered a completion at all. If you enable
allowJs, this should auto complete to the.jsfile assuming you have"typescript.preferences.importModuleSpecifierEnding": "js".What I think is a bug, is that we complete with the
.tsending when there is also a.tsfile with the same name present. It looks like theimportModuleSpecifierEndingsetting is just used to decide whether or not we remove the extension on string literal completion in the import. IfallowJsis false, the.jsimport is not found, but we still offer the completion for the.tsfile with the same name, but with the extension (incorrectly) attached. I think in this case we should offer the completion without any extension.cc Andrew Branch (@andrewbranch) as I'm not super familiar with how module resolution works.
Edit: after more investigation I see that auto import completion (not import string completion) adds the
.jsextension even ifallowJsis false, if there is a.tsfile present with the same name. I'm no longer sure if it is intended behavior or not to offer import completions with.jswithallowJs: false...Tyriar commentedon Jun 15, 2021
I can't remember the exact reason but using .js fixed a compile/bundling issue for me at some point. I use tsc and then webpack on its output, could be related to workers, dynamic imports or es modules.
andrewbranch commentedon Jun 15, 2021
Auto imports are working correctly and these path completions are working incorrectly. You’re never allowed to write
.tsin a module specifier. You are always allowed to write a module specifier for a TS file as a.jspath, and you are allowed to write an import for an actual JS source file only ifallowJsis enabled. The example shown here is for a TS source file, so the completion should be shown asnumber.jsregardless of theallowJssetting.