diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 830bf2e05cdbf..ad8c6b999154e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12929,8 +12929,8 @@ namespace ts { covariant = !covariant; } // Always substitute on type parameters, regardless of variance, since even - // in contravarrying positions, they may be reliant on subtuted constraints to be valid - if ((covariant || type.flags & TypeFlags.TypeParameter) && parent.kind === SyntaxKind.ConditionalType && node === (parent).trueType) { + // in contravariant positions, they may rely on substituted constraints to be valid + if ((covariant || type.flags & TypeFlags.TypeVariable) && parent.kind === SyntaxKind.ConditionalType && node === (parent).trueType) { const constraint = getImpliedConstraint(type, (parent).checkType, (parent).extendsType); if (constraint) { constraints = append(constraints, constraint); diff --git a/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.js b/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.js index b3e236ff9cd7b..6110706773f66 100644 --- a/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.js +++ b/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.js @@ -32,9 +32,18 @@ fn2(m => m(42)); // webidl-conversions example where substituion must occur, despite contravariance of the position // due to the invariant usage in `Parameters` -type X = V extends (...args: any[]) => any ? (...args: Parameters) => void : Function; +type X = V extends (...args: any[]) => any ? (...args: Parameters) => void : Function; + +// vscode - another `Parameters` example +export type AddFirstParameterToFunctions = { + [K in keyof Target]: Target[K] extends (...args: any[]) => void + ? (...args: Parameters) => void + : void +}; //// [callOfConditionalTypeWithConcreteBranches.js] +"use strict"; +exports.__esModule = true; function fn(arg) { // Expected: OK // Actual: Cannot convert 10 to number & T diff --git a/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.symbols b/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.symbols index dbed1d31aa944..c80fd32a03af1 100644 --- a/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.symbols +++ b/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.symbols @@ -103,3 +103,23 @@ type X = V extends (...args: any[]) => any ? (...args: Parameters) => void >V : Symbol(V, Decl(callOfConditionalTypeWithConcreteBranches.ts, 33, 7)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +// vscode - another `Parameters` example +export type AddFirstParameterToFunctions = { +>AddFirstParameterToFunctions : Symbol(AddFirstParameterToFunctions, Decl(callOfConditionalTypeWithConcreteBranches.ts, 33, 92)) +>Target : Symbol(Target, Decl(callOfConditionalTypeWithConcreteBranches.ts, 36, 41)) + + [K in keyof Target]: Target[K] extends (...args: any[]) => void +>K : Symbol(K, Decl(callOfConditionalTypeWithConcreteBranches.ts, 37, 3)) +>Target : Symbol(Target, Decl(callOfConditionalTypeWithConcreteBranches.ts, 36, 41)) +>Target : Symbol(Target, Decl(callOfConditionalTypeWithConcreteBranches.ts, 36, 41)) +>K : Symbol(K, Decl(callOfConditionalTypeWithConcreteBranches.ts, 37, 3)) +>args : Symbol(args, Decl(callOfConditionalTypeWithConcreteBranches.ts, 37, 42)) + + ? (...args: Parameters) => void +>args : Symbol(args, Decl(callOfConditionalTypeWithConcreteBranches.ts, 38, 9)) +>Parameters : Symbol(Parameters, Decl(lib.es5.d.ts, --, --)) +>Target : Symbol(Target, Decl(callOfConditionalTypeWithConcreteBranches.ts, 36, 41)) +>K : Symbol(K, Decl(callOfConditionalTypeWithConcreteBranches.ts, 37, 3)) + + : void +}; diff --git a/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.types b/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.types index 2bee57b8fe796..412986f9e27e0 100644 --- a/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.types +++ b/tests/baselines/reference/callOfConditionalTypeWithConcreteBranches.types @@ -97,3 +97,15 @@ type X = V extends (...args: any[]) => any ? (...args: Parameters) => void >args : any[] >args : Parameters +// vscode - another `Parameters` example +export type AddFirstParameterToFunctions = { +>AddFirstParameterToFunctions : AddFirstParameterToFunctions + + [K in keyof Target]: Target[K] extends (...args: any[]) => void +>args : any[] + + ? (...args: Parameters) => void +>args : Parameters + + : void +}; diff --git a/tests/cases/compiler/callOfConditionalTypeWithConcreteBranches.ts b/tests/cases/compiler/callOfConditionalTypeWithConcreteBranches.ts index 91b236ef61fbd..6db7542d1805e 100644 --- a/tests/cases/compiler/callOfConditionalTypeWithConcreteBranches.ts +++ b/tests/cases/compiler/callOfConditionalTypeWithConcreteBranches.ts @@ -31,4 +31,11 @@ fn2(m => m(42)); // webidl-conversions example where substituion must occur, despite contravariance of the position // due to the invariant usage in `Parameters` -type X = V extends (...args: any[]) => any ? (...args: Parameters) => void : Function; \ No newline at end of file +type X = V extends (...args: any[]) => any ? (...args: Parameters) => void : Function; + +// vscode - another `Parameters` example +export type AddFirstParameterToFunctions = { + [K in keyof Target]: Target[K] extends (...args: any[]) => void + ? (...args: Parameters) => void + : void +}; \ No newline at end of file