Add refactoring to use default import#19659
Add refactoring to use default import#196592 commits merged into
Conversation
44919e8 to
6d49aeb
Compare
|
|
||
| const useDefaultImport: Refactor = { | ||
| name: actionName, | ||
| description: actionName, |
There was a problem hiding this comment.
this should be localizable, e.g. getLocaleSpecificMessage(Diagnostics.Convert_to_default_import),
name should be not be modified, it should act as an identifier
There was a problem hiding this comment.
If the locale is changed after boot this will have the wrong description, since this object is created immediately. This would affect other refactors too. Should we fix this?
| function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined { | ||
| const { file, startPosition, program } = context; | ||
|
|
||
| if (!program.getCompilerOptions().allowSyntheticDefaultImports) { |
There was a problem hiding this comment.
@weswigham we will need to add your new commandline argument to enable the interop behavior here as well.
There was a problem hiding this comment.
If you go look at the PR, I have a similar but more precise quickfix which triggers on a diagnostic added when a namespace object is misused.
There was a problem hiding this comment.
I think we need both. The quick fix for the error, the refactoring for style change even without an error.
mhegazy
left a comment
There was a problem hiding this comment.
We need another one for .js files to convert require to either import d from "mod" or import * from "mod" based on the shape of the module
|
@mhegazy Could you clarify what you mean by "based on the shape of the module"? When should we use a namespace import instead of a default import? |
|
Logged #19719 to track that |
Fixes #19261
Currently this will only activate if
--allowSyntheticDefaultImportsis enabled.