-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixed an issue with type-only import promoting #55365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jakebailey
merged 2 commits into
microsoft:main
from
Andarist:fix/codefix-promote-type-only
Sep 18, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference path="fourslash.ts" /> | ||
// @module: es2015 | ||
|
||
// https://github.com/microsoft/TypeScript/issues/55363 | ||
|
||
// @Filename: index.ts | ||
//// import { TwistyAlgEditor, type TwistyPlayer } from "./other-file"; | ||
//// new TwistyPlayer(); | ||
|
||
// @Filename: other-file.ts | ||
//// export class TwistyAlgEditor {} | ||
//// export class TwistyPlayer {} | ||
|
||
verify.codeFix({ | ||
index: 0, | ||
description: [ts.Diagnostics.Remove_type_from_import_of_0_from_1.message, "TwistyPlayer", "./other-file"], | ||
applyChanges: true, | ||
newFileContent: | ||
`import { TwistyAlgEditor, TwistyPlayer } from "./other-file"; | ||
new TwistyPlayer();` | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that there is an argument to be made here that this codefix shouldn't change the position of the promoted import. This is a separate action. I left this as-is though, as I assume that this was implemented this way for a reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it might be annoying to users if they have their imports already sorted such that type-only imports are grouped separately from regular ones; promoting a type import will leave it in the wrong position in the list. Particularly if the user is relying on auto-imports which automatically puts them in the correct place, it'd be frustrating to have this one code fix that requires triggering Organize Imports manually when in every other case it's automatic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason that it moves in the list currently is that TS's organize/auto-imports always sorts
type
imports at end, but otherwise they're in order. Of course, via #55269 and #52820, this will become even more configurable. So effectively, any operation that does anything to imports (adding, removing, changing modifiers) has to go through some sort of sorting code to determine whether or not the user opted into sorting something in a particular way. Thankfully, the main goal of that configurability is enabling people to stick type imports inline such that these modifier changes don't affect sorting at all, which is nice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you happen to know if renaming exported symbols also sorts the relevant imports that use them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure it doesn't, no; my understanding is that rename is more of an "in place transform" and it doesn't even check that the name you're giving it is syntactically valid.