Skip to content

Fix organizeImports with type-only imports #36807

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
merged 1 commit into from
Feb 14, 2020

Conversation

andrewbranch
Copy link
Member

Fixes #36798

Not sure how I missed this originally 😱

There is room for opinions on how type-only imports should be sorted relative to non-type-only imports, but I’d suggest the time for those opinions is not 80 minutes before our release build 😄

Tip: review ignoring whitespace

@DanielRosenwasser
Copy link
Member

@typescript-bot cherry-pick this to release-3.8

typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this pull request Feb 14, 2020
Component commits:
ec495ab Fix organizeImports with type-only imports
@typescript-bot
Copy link
Collaborator

Hey @DanielRosenwasser, I've opened #36810 for you.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Feb 14, 2020

Fine I'll do it myself you annoying robot nvm thank u robot frend

const sortedImports = parseImports(
`import type { x } from "lib";`,
`import type * as y from "lib";`,
`import type z from "lib";`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cant this mix with import type { x, default as z} from "lib just like normal import statement ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we decided it would be ambiguous what the "type" keyword applied to and forced explicitness.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could, but I’m not confident that’s desirable. My personal preference for readability would probably be what’s represented here in the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewbranch Consider adding a comment about this: // Type-only imports are not allowed to combine (for readability). Maybe on the test too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably possible at a later pass, but seems reasonable to leave it the way it is now until we get further feedback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a stylistic choice in organizeImports, I don't think "allowed" is the right word - I definitely read that as a language restriction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment in the implementation was actually referring to the language restriction, ignoring the possibility of rewriting the default as a named import. I’ll follow up to clarify.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for the test coverage!

@andrewbranch andrewbranch merged commit b82d320 into microsoft:master Feb 14, 2020
@andrewbranch andrewbranch deleted the bug/36798 branch February 14, 2020 23:25
DanielRosenwasser pushed a commit that referenced this pull request Feb 14, 2020
Component commits:
ec495ab Fix organizeImports with type-only imports

Co-authored-by: Andrew Branch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[3.8] Organize imports combines export and export type declarations
5 participants