microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.19k stars 28.55k forks source link

TypeScript: autoimporting imports from .js files #125624

Closed ImRodry closed 3 years ago

ImRodry commented 3 years ago

Issue Type: Bug

When writing the name of a function or parameter that was exported in a different file, VSCode asks you if you want to automatically import said function or parameter. If you choose to do this on typescript, the import statement will include ".js" at the end of the file, when there should be no extension at all due to the nature of typescript.

VS Code version: Code 1.56.2 (054a9295330880ed74ceaedda236253b4f39a335, 2021-05-12T17:13:13.157Z) OS version: Windows_NT x64 10.0.19043

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz (12 x 3192)| |GPU Status|2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled| |Load (avg)|undefined| |Memory (System)|19.89GB (8.21GB free)| |Process Argv|D:\\Users\\rodri\\Documents\\GitHub\\hypixel-translators-bot --crash-reporter-id 1aa51578-c79e-468f-b062-c24334e21918| |Screen Reader|no| |VM|0%|
Extensions (10) Extension|Author (truncated)|Version ---|---|--- gitlens|eam|11.4.1 EditorConfig|Edi|0.16.4 prettier-vscode|esb|6.4.0 vscode-graphql|Gra|0.3.16 vscode-env|Iro|0.1.0 python|ms-|2021.5.842923320 vsliveshare|ms-|1.0.4360 vetur|oct|0.34.1 vscodeintellicode|Vis|1.2.14 minecraft-lang-colorizer|zz5|1.0.0
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383cf:30185419 vspyt653:30270858 pythonvspyt602:30300191 vspor879:30202332 vspor708:30202333 vspor363:30204092 pythonvspyt639:30300192 pythontb:30283811 vspre833cf:30267465 pythonptprofiler:30281270 vshan820:30294714 pythondataviewer:30285071 vscus158cf:30286554 vscgsv2:30307504 vscorehov:30309549 vscod805cf:30301675 binariesv517:30312825 ```
IllusionMH commented 3 years ago

Should be controlled by settings typescript.preferences.importModuleSpecifierEnding and javascript.preferences.importModuleSpecifierEnding. Do you have it changed?

What are you target and module settings? TS allows for .js extension in imports even for .ts files because it doesn't rewrire imports during output and ES modules require proper paths (including extension)

See also https://github.com/microsoft/TypeScript/pull/40637

ImRodry commented 3 years ago

I didn’t know those settings existed and now that I changed them it seems to work, thanks! About the second question, mu target is es2020 and module is commonjs. Will close this then since it was never an issue apparently :)

IllusionMH commented 3 years ago

Not sure if .js is expected for commonjs modules, but glad that setting works for you.

ImRodry commented 3 years ago

Well I had my settings on auto and no project settings so I’m not really sure why this was happening since it should default to shortest but if it works it works :)