-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Organize type imports #55269
Organize type imports #55269
Changes from 5 commits
14afb68
f44793d
e720377
3652bce
ee32e43
d47d1b6
bb47232
44b07dd
4a83f8c
489e92a
11929fe
63dcdb6
4560a6b
42033fc
dca9ba6
d408f5a
7902488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @verbatimModuleSyntax: true | ||
// @target: esnext | ||
|
||
// @Filename: /foo.ts | ||
//// export const A = 1; | ||
//// export type B = { x: number }; | ||
//// export type C = 1; | ||
//// export class D = { y: string }; | ||
|
||
// @Filename: /test.ts | ||
//// import { A, D, type C } from './foo'; | ||
//// const b: B/**/ | C; | ||
//// console.log(A, D); | ||
|
||
goTo.marker(""); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, D, type C, type B } from './foo'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this one turn out to have C first? The next one doesn't which feels odd. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's adding |
||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "inline" } | ||
); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, D, type C, type B } from './foo'; | ||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "last" } | ||
); | ||
iisaduan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
verify.importFixAtPosition([ | ||
`import { A, D, type C, type B } from './foo'; | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "first" } | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @verbatimModuleSyntax: true | ||
// @target: esnext | ||
|
||
// @Filename: /foo.ts | ||
//// export const A = 1; | ||
//// export type B = { x: number }; | ||
//// export type C = 1; | ||
//// export class D = { y: string }; | ||
|
||
// @Filename: /test.ts | ||
//// import { A, type C, D } from './foo'; | ||
//// const b: B/**/ | C; | ||
//// console.log(A, D); | ||
|
||
goTo.marker(""); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, type B, type C, D } from './foo'; | ||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "inline" } | ||
); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, type C, D, type B } from './foo'; | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "last" } | ||
); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, type C, D, type B } from './foo'; | ||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "first" } | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @allowSyntheticDefaultImports: true | ||
// @moduleResolution: node | ||
// @noUnusedLocals: true | ||
// @target: es2018 | ||
|
||
//// import { A } from "foo"; | ||
//// import { type B } from "foo"; | ||
//// import { C } from "foo"; | ||
//// import { type E } from "foo"; | ||
//// import { D } from "foo"; | ||
//// | ||
//// console.log(A, B, C, D, E); | ||
|
||
verify.organizeImports( | ||
`import { A, type B, C, D, type E } from "foo"; | ||
|
||
console.log(A, B, C, D, E);` | ||
); | ||
|
||
verify.organizeImports( | ||
`import { A, type B, C, D, type E } from "foo"; | ||
|
||
console.log(A, B, C, D, E);`, | ||
undefined, | ||
{ organizeImportsTypeOrder : "inline" } | ||
); | ||
|
||
|
||
verify.organizeImports( | ||
`import { type B, type E, A, C, D } from "foo"; | ||
|
||
console.log(A, B, C, D, E);`, | ||
undefined, | ||
{ organizeImportsTypeOrder : "first" } | ||
); | ||
|
||
verify.organizeImports( | ||
`import { A, C, D, type B, type E } from "foo"; | ||
|
||
console.log(A, B, C, D, E);`, | ||
undefined, | ||
{ organizeImportsTypeOrder : "last" } | ||
); |
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 current default is effectively "last"; for backwards compat I'm thinking we should probaby keep that?
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.
That makes sense to me, and is inline with the past changes to organize imports
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.
Of course, changing the default to inline was what I was doing when I was attempting to make this change, was very helpful in debugging.