mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-20 10:29:36 -06:00
Fix quick fix for isolatedDeclarations to keep trailing unknown in generics (#61227)
This commit is contained in:
parent
71b16ea186
commit
3f416e0f52
@ -621,6 +621,9 @@ function endOfRequiredTypeParameters(checker: TypeChecker, type: GenericType): n
|
||||
const fullTypeArguments = type.typeArguments;
|
||||
const target = type.target;
|
||||
for (let cutoff = 0; cutoff < fullTypeArguments.length; cutoff++) {
|
||||
if (target.localTypeParameters?.[cutoff].constraint === undefined) {
|
||||
continue;
|
||||
}
|
||||
const typeArguments = fullTypeArguments.slice(0, cutoff);
|
||||
const filledIn = checker.fillMissingTypeArguments(typeArguments, target.typeParameters, cutoff, /*isJavaScriptImplicitAny*/ false);
|
||||
if (filledIn.every((fill, i) => fill === fullTypeArguments[i])) {
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @isolatedDeclarations: true
|
||||
// @declaration: true
|
||||
// @lib: es2015
|
||||
////
|
||||
////let x: unknown;
|
||||
////export const s = new Set([x]);
|
||||
////
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add annotation of type 'Set<unknown>'",
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`
|
||||
let x: unknown;
|
||||
export const s: Set<unknown> = new Set([x]);
|
||||
`,
|
||||
});
|
||||
@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @isolatedDeclarations: true
|
||||
// @declaration: true
|
||||
// @lib: es2015
|
||||
////
|
||||
////export const s = new Set<unknown>();
|
||||
////
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add annotation of type 'Set<unknown>'",
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`
|
||||
export const s: Set<unknown> = new Set<unknown>();
|
||||
`,
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @isolatedDeclarations: true
|
||||
// @declaration: true
|
||||
////
|
||||
////export interface Foo<S = string, T = unknown, U = number> {}
|
||||
////export function g(x: Foo<number, unknown, number>) { return x; }
|
||||
////
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add return type 'Foo<number>'",
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`
|
||||
export interface Foo<S = string, T = unknown, U = number> {}
|
||||
export function g(x: Foo<number, unknown, number>): Foo<number> { return x; }
|
||||
`,
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @isolatedDeclarations: true
|
||||
// @declaration: true
|
||||
////
|
||||
////export interface Foo<S = string, T = unknown> {}
|
||||
////export function f(x: Foo<string, unknown>) { return x; }
|
||||
////
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add return type 'Foo'",
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`
|
||||
export interface Foo<S = string, T = unknown> {}
|
||||
export function f(x: Foo<string, unknown>): Foo { return x; }
|
||||
`,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user