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
TS auto import should support configuring whether a star or a qualified import is used. #19630
Having that as a separate refactoring makes sense, nevertheless I would like to have this right in the first place and not me picking an entry from a completion list and then being forced to execute another refactorings. In another tool I worked on ( :-) ) we had a configuration comparable to this to control the import generation:
For example, now if I type resolve, VS Code auto suggests millions of resolve from all libraries. This is not helpful:
For me, I usually have this
import*aspathfrom'path'path.resolve(...)
However now path. doesn't have any auto import associated with suggestions.
I hope path. can generate completion items that when accepted, add automatic imports to top.
The expected behavior is:
Type path.
VS Code should auto complete, based on either type definition at @types/node or the Automatic Type Acquisition
When user accepts path.resolve, add to top of file import * as path from 'path'
I think if one types resolve, auto import import { resolve } from 'path' makes sense. However when one types path.resolve, auto import should do import * as path from 'path'.
Reacted by Jian Guo, Xiaoyi, phiresky, wildeyes, Ryan Koval, Tomas Zaluckij, Přemysl Karbula and Quentin Calvez
In my experience Qualified import makes for more readable code in most cases and its the import pattern advocated for in Haskell, Python, and language-enforced in Go. Likely other language too, I just don't know. Looking forward to support for this. I think its unfortunate qualified is not the default but neither is strict mode etc. so its just another flag to add the many already needed for a solid baseline in TS... not a huge deal I guess. Though its a missed opportunity to nudge the community in a better direction in my honest personal opinion :)
Reacted by Chiawen Chen, wildeyes, Tomas Zaluckij, Richard Musiol and Quentin Calvez
I would be happy if I could write an item name, find it in the completion list, press <SOME_MODIFIER>+Tab/Enter and have it import the thing as qualified. You could pick the name from file/module the item belongs to, with a kebab-/snakecase converted to camelcase. Rename refactoring could be then used on the qualified name if needed.
i.e.
getName completion could become:
import * as User from `some/module/User`
...
User.getName
Reacted by Thomas, Jian Guo, Xiaoyi, Kevin Nolan, John Mick, Chiawen Chen, phiresky, Jason Kuhrt and wildeyes
I think this one needs some thought. For example, what name should we use for * from X?
Consider https://jsdoc.app/tags-module.html. We can define the @module tags in the single file or the index.ts under the directory, and then, it should be warned if there are multiple different @module under a directory with index.ts
Activity
mjbvz commentedon Nov 1, 2017
I think this one needs some thought. For example, what name should we use for
* from X?DanielRosenwasser commentedon Nov 1, 2017
See #19260
dbaeumer commentedon Nov 1, 2017
Having that as a separate refactoring makes sense, nevertheless I would like to have this right in the first place and not me picking an entry from a completion list and then being forced to execute another refactorings. In another tool I worked on ( :-) ) we had a configuration comparable to this to control the import generation:
Default would IMO still be a qualified import.
mhegazy commentedon Nov 1, 2017
you mean
import *? curious why?dbaeumer commentedon Nov 3, 2017
Mohamed Hegazy (@mhegazy) sorry used wrong words. Default should be
import { .... } fromoctref commentedon May 11, 2018
Copying my original problem here:
For example, now if I type
resolve, VS Code auto suggests millions ofresolvefrom all libraries. This is not helpful:For me, I usually have this
However now
path.doesn't have any auto import associated with suggestions.I hope
path.can generate completion items that when accepted, add automatic imports to top.The expected behavior is:
path.@types/nodeor the Automatic Type Acquisitionpath.resolve, add to top of fileimport * as path from 'path'I think if one types
resolve, auto importimport { resolve } from 'path'makes sense. However when one typespath.resolve, auto import should doimport * as path from 'path'.jasonkuhrt commentedon Jun 20, 2018
In my experience Qualified import makes for more readable code in most cases and its the import pattern advocated for in Haskell, Python, and language-enforced in Go. Likely other language too, I just don't know. Looking forward to support for this. I think its unfortunate qualified is not the default but neither is
strictmode etc. so its just another flag to add the many already needed for a solid baseline in TS... not a huge deal I guess. Though its a missed opportunity to nudge the community in a better direction in my honest personal opinion :)OliverJAsh commentedon Aug 8, 2019
Related: #23830
katis commentedon Nov 12, 2019
I would be happy if I could write an item name, find it in the completion list, press
<SOME_MODIFIER>+Tab/Enterand have it import the thing as qualified. You could pick the name from file/module the item belongs to, with a kebab-/snakecase converted to camelcase. Rename refactoring could be then used on the qualified name if needed.i.e.
getNamecompletion could become:JuoCode commentedon Mar 9, 2023
Consider https://jsdoc.app/tags-module.html. We can define the
@moduletags in the single file or the index.ts under the directory, and then, it should be warned if there are multiple different@moduleunder a directory with index.tswildeyes commentedon May 23, 2023
Anyone know of an extension that can do this right now?
OliverJAsh commentedon May 24, 2023
wildeyes You might find this useful: https://github.com/unsplash/ts-namespace-import-plugin