-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop unnecessary type arguments in the isolated declarations quick fix (
#59665) Co-authored-by: Jake Bailey <[email protected]> Co-authored-by: Nathan Shively-Sanders <[email protected]>
- Loading branch information
1 parent
52eaa7b
commit 8230bc6
Showing
10 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
15 changes: 15 additions & 0 deletions
15
tests/cases/fourslash/codeFixMissingTypeAnnotationOnExports50-generics-with-default.ts
This file contains 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,15 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
// @isolatedDeclarations: true | ||
// @declaration: true | ||
// @lib: es2015 | ||
////let x: Iterator<number>; | ||
////export const y = x; | ||
|
||
verify.codeFix({ | ||
description: "Add annotation of type 'Iterator<number>'", | ||
index: 0, | ||
newFileContent: | ||
`let x: Iterator<number>; | ||
export const y: Iterator<number> = x;`, | ||
}); |
19 changes: 19 additions & 0 deletions
19
...sh/codeFixMissingTypeAnnotationOnExports51-slightly-more-complex-generics-with-default.ts
This file contains 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,19 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
// @isolatedDeclarations: true | ||
// @declaration: true | ||
|
||
////export interface Foo<T, U = T[]> {} | ||
////export function foo(x: Foo<string>) { | ||
//// return x; | ||
////} | ||
|
||
verify.codeFix({ | ||
description: "Add return type 'Foo<string>'", | ||
index: 0, | ||
newFileContent: | ||
`export interface Foo<T, U = T[]> {} | ||
export function foo(x: Foo<string>): Foo<string> { | ||
return x; | ||
}`, | ||
}); |
23 changes: 23 additions & 0 deletions
23
tests/cases/fourslash/codeFixMissingTypeAnnotationOnExports52-generics-oversimplification.ts
This file contains 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,23 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
// In the abstract, we might prefer the inferred return type annotation to | ||
// be identical to the parameter type (with 2 type parameters). | ||
// Our current heuristic to avoid overly complex types in this case creates | ||
// "overly simple" types, but this tradeoff seems reasonable. | ||
|
||
// @isolatedDeclarations: true | ||
// @declaration: true | ||
////export interface Foo<T, U = T[]> {} | ||
////export function foo(x: Foo<string, string[]>) { | ||
//// return x; | ||
////} | ||
|
||
verify.codeFix({ | ||
description: "Add return type 'Foo<string>'", | ||
index: 0, | ||
newFileContent: | ||
`export interface Foo<T, U = T[]> {} | ||
export function foo(x: Foo<string, string[]>): Foo<string> { | ||
return x; | ||
}`, | ||
}); |
21 changes: 21 additions & 0 deletions
21
tests/cases/fourslash/codeFixMissingTypeAnnotationOnExports53-nested-generic-types.ts
This file contains 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'/> | ||
|
||
// Our current heursitic to avoid overly verbose generic types | ||
// doesn't handle generic types nested inside other types. | ||
|
||
// @isolatedDeclarations: true | ||
// @declaration: true | ||
////export interface Foo<T, U = T[]> {} | ||
////export function foo(x: Map<number, Foo<string>>) { | ||
//// return x; | ||
////} | ||
|
||
verify.codeFix({ | ||
description: "Add return type 'Map<number, Foo<string, string[]>>'", | ||
index: 0, | ||
newFileContent: | ||
`export interface Foo<T, U = T[]> {} | ||
export function foo(x: Map<number, Foo<string>>): Map<number, Foo<string, string[]>> { | ||
return x; | ||
}`, | ||
}); |
17 changes: 17 additions & 0 deletions
17
tests/cases/fourslash/codeFixMissingTypeAnnotationOnExports54-generator-generics.ts
This file contains 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,17 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
// @isolatedDeclarations: true | ||
// @declaration: true | ||
// @lib: es2015 | ||
//// export function foo(x: Generator<number>) { | ||
//// return x; | ||
//// } | ||
|
||
verify.codeFix({ | ||
description: "Add return type 'Generator<number>'", | ||
index: 0, | ||
newFileContent: | ||
`export function foo(x: Generator<number>): Generator<number> { | ||
return x; | ||
}` | ||
}); |
17 changes: 17 additions & 0 deletions
17
tests/cases/fourslash/codeFixMissingTypeAnnotationOnExports55-generator-return.ts
This file contains 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,17 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
// @isolatedDeclarations: true | ||
// @declaration: true | ||
// @lib: es2015 | ||
//// export function *foo() { | ||
//// yield 5; | ||
//// } | ||
|
||
verify.codeFix({ | ||
description: "Add return type 'Generator<number, void, unknown>'", | ||
index: 0, | ||
newFileContent: | ||
`export function *foo(): Generator<number, void, unknown> { | ||
yield 5; | ||
}` | ||
}); |