-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Drop unnecessary type arguments in the isolated declarations quick fix #59665
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
Changes from all commits
dd29423
6f8e37d
b0bc68f
de61d6d
b0b1e02
943761b
d53552f
77ac42f
71c092a
14deb8e
a603aa2
4e21657
cd0cd4e
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,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;`, | ||
}); |
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; | ||
}`, | ||
}); |
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; | ||
}`, | ||
}); |
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; | ||
}`, | ||
}); |
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> { | ||
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. To be clear I was meaning to write 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. Ah, OK, added. It's not technically related to the rest of this PR since it gets inferred a precise return that needs all 3 type arguments, but it's a good case to include in the test suite anyway. |
||
return x; | ||
}` | ||
}); |
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; | ||
}` | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.