-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Account for type parameters in missing function codefix #49727
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
sandersn
merged 10 commits into
microsoft:main
from
JoshuaKGoldberg:codefix-missing-function-generic
Jul 26, 2022
+444
−10
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e157bff
Account for type parameters in missing function codefix
JoshuaKGoldberg caff21e
Apply suggestions from code review
JoshuaKGoldberg 41a72c8
WIP
JoshuaKGoldberg bd14701
Merge branch 'main' into codefix-missing-function-generic
JoshuaKGoldberg 456693d
Synthesize new type parameters instead of deep unions and intersections
JoshuaKGoldberg ff6fc40
Pass along type parameter constraints
JoshuaKGoldberg 13b3f94
E.T. phone home
JoshuaKGoldberg aaa7f2c
Clean up comments just a bit
JoshuaKGoldberg b1d35a3
Merge branch 'main' into codefix-missing-function-generic
JoshuaKGoldberg 9773280
Only widen the instance type sometimes
JoshuaKGoldberg 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
22 changes: 22 additions & 0 deletions
22
tests/cases/fourslash/incompleteFunctionCallCodefixTypeKeyof.ts
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,22 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
////function existing<T>(value: T) { | ||
//// const keyofTypeof = Object.keys(value)[0] as keyof T; | ||
//// added/*1*/(keyofTypeof); | ||
////} | ||
|
||
goTo.marker("1"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added'", | ||
index: 0, | ||
newFileContent: `function existing<T>(value: T) { | ||
const keyofTypeof = Object.keys(value)[0] as keyof T; | ||
added(keyofTypeof); | ||
} | ||
|
||
function added(keyofTypeof: string | number | symbol) { | ||
throw new Error("Function not implemented."); | ||
} | ||
`, | ||
}); |
20 changes: 20 additions & 0 deletions
20
tests/cases/fourslash/incompleteFunctionCallCodefixTypeParameter.ts
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,20 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
////function existing<T>(value: T) { | ||
//// added/*1*/(value); | ||
////} | ||
|
||
goTo.marker("1"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added'", | ||
index: 0, | ||
newFileContent: `function existing<T>(value: T) { | ||
added(value); | ||
} | ||
|
||
function added<T>(value: T) { | ||
throw new Error("Function not implemented."); | ||
} | ||
`, | ||
}); |
20 changes: 20 additions & 0 deletions
20
tests/cases/fourslash/incompleteFunctionCallCodefixTypeParameterArgumentDifferent.ts
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,20 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
////function existing<T>(value: T) { | ||
//// added/*1*/<T, string>(value, ""); | ||
////} | ||
|
||
goTo.marker("1"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added'", | ||
index: 0, | ||
newFileContent: `function existing<T>(value: T) { | ||
added<T, string>(value, ""); | ||
} | ||
|
||
function added<T, U>(value: T, arg1: string) { | ||
throw new Error("Function not implemented."); | ||
} | ||
`, | ||
}); |
20 changes: 20 additions & 0 deletions
20
tests/cases/fourslash/incompleteFunctionCallCodefixTypeParameterArgumentSame.ts
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,20 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
////function existing<T>(value: T) { | ||
//// added/*1*/<T>(value, value); | ||
////} | ||
|
||
goTo.marker("1"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added'", | ||
index: 0, | ||
newFileContent: `function existing<T>(value: T) { | ||
added<T>(value, value); | ||
} | ||
|
||
function added<T>(value: T, value1: T) { | ||
throw new Error("Function not implemented."); | ||
} | ||
`, | ||
}); |
20 changes: 20 additions & 0 deletions
20
tests/cases/fourslash/incompleteFunctionCallCodefixTypeParameterConstrained.ts
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,20 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
////function existing<T extends string>(value: T) { | ||
//// added/*1*/(value); | ||
////} | ||
|
||
goTo.marker("1"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added'", | ||
index: 0, | ||
newFileContent: `function existing<T extends string>(value: T) { | ||
added(value); | ||
} | ||
|
||
function added<T extends string>(value: T) { | ||
throw new Error("Function not implemented."); | ||
} | ||
`, | ||
}); |
24 changes: 24 additions & 0 deletions
24
tests/cases/fourslash/incompleteFunctionCallCodefixTypeParameterNarrowed.ts
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,24 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
////function existing<T>(value: T) { | ||
//// if (typeof value === "number") { | ||
//// added/*1*/(value); | ||
//// } | ||
////} | ||
|
||
goTo.marker("1"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added'", | ||
index: 0, | ||
newFileContent: `function existing<T>(value: T) { | ||
if (typeof value === "number") { | ||
added(value); | ||
} | ||
} | ||
|
||
function added<T>(value: T) { | ||
throw new Error("Function not implemented."); | ||
} | ||
`, | ||
}); |
43 changes: 43 additions & 0 deletions
43
tests/cases/fourslash/incompleteFunctionCallCodefixTypeParameterVariable.ts
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,43 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
////function e<T extends "phone" | "home">() { | ||
//// let et: T = 'phone' | ||
//// added1/*1*/(et) | ||
//// et = 'home' | ||
//// added2/*2*/(et) | ||
////} | ||
|
||
goTo.marker("1"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added1'", | ||
index: 0, | ||
newFileContent: `function e<T extends "phone" | "home">() { | ||
let et: T = 'phone' | ||
added1(et) | ||
et = 'home' | ||
added2(et) | ||
} | ||
|
||
function added1(et: string) { | ||
throw new Error("Function not implemented.") | ||
} | ||
`, | ||
}); | ||
|
||
goTo.marker("2"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added1'", | ||
index: 0, | ||
newFileContent: `function e<T extends "phone" | "home">() { | ||
let et: T = 'phone' | ||
added1(et) | ||
et = 'home' | ||
added2(et) | ||
} | ||
|
||
function added1(et: string) { | ||
throw new Error("Function not implemented.") | ||
} | ||
`, | ||
}); |
20 changes: 20 additions & 0 deletions
20
tests/cases/fourslash/incompleteFunctionCallCodefixTypeParameters.ts
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,20 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
////function existing<T1, T, T2>(t1: T1, t: T, t2a: T2, t2b: T2, t2c: T2) { | ||
//// added/*1*/(t2a, t2b, t2c, t1, t, t2a, t2c, t2b); | ||
////} | ||
|
||
goTo.marker("1"); | ||
verify.codeFix({ | ||
description: "Add missing function declaration 'added'", | ||
index: 0, | ||
newFileContent: `function existing<T1, T, T2>(t1: T1, t: T, t2a: T2, t2b: T2, t2c: T2) { | ||
added(t2a, t2b, t2c, t1, t, t2a, t2c, t2b); | ||
} | ||
|
||
function added<T2, T1, T>(t2a: T2, t2b: T2, t2c: T2, t1: T1, t: T, t2a1: T2, t2c1: T2, t2b1: T2) { | ||
throw new Error("Function not implemented."); | ||
} | ||
`, | ||
}); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.