diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8e4b9e48a28..3d709be779f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14613,7 +14613,7 @@ namespace ts { combinedMapper = mergeTypeMappers(mapper, context.mapper); } // Instantiate the extends type including inferences for 'infer T' type parameters - const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType; + const inferredExtendsType = combinedMapper ? instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), combinedMapper) : extendsType; // We attempt to resolve the conditional type only when the check and extends types are non-generic if (!checkTypeInstantiable && !isGenericObjectType(inferredExtendsType) && !isGenericIndexType(inferredExtendsType)) { // Return falseType for a definitely false extends check. We check an instantiations of the two diff --git a/tests/baselines/reference/nondistributiveConditionalTypeInfer.js b/tests/baselines/reference/nondistributiveConditionalTypeInfer.js new file mode 100644 index 00000000000..968f3c1a4d7 --- /dev/null +++ b/tests/baselines/reference/nondistributiveConditionalTypeInfer.js @@ -0,0 +1,16 @@ +//// [nondistributiveConditionalTypeInfer.ts] +type _R = [T] extends [{ _R: (_: infer R) => void }] ? R : never; +type _E = [T] extends [{ _E: () => infer E }] ? E : never; +type _A = [T] extends [{ _A: () => infer A }] ? A : never; + +interface Sync { + _R: (_: R) => void; + _E: () => E; + _A: () => A; +} + +type R = _R>; +type E = _E>; +type A = _A>; + +//// [nondistributiveConditionalTypeInfer.js] diff --git a/tests/baselines/reference/nondistributiveConditionalTypeInfer.symbols b/tests/baselines/reference/nondistributiveConditionalTypeInfer.symbols new file mode 100644 index 00000000000..133abc6c6a4 --- /dev/null +++ b/tests/baselines/reference/nondistributiveConditionalTypeInfer.symbols @@ -0,0 +1,61 @@ +=== tests/cases/compiler/nondistributiveConditionalTypeInfer.ts === +type _R = [T] extends [{ _R: (_: infer R) => void }] ? R : never; +>_R : Symbol(_R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 0)) +>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 0, 8)) +>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 0, 8)) +>_R : Symbol(_R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 27)) +>_ : Symbol(_, Decl(nondistributiveConditionalTypeInfer.ts, 0, 33)) +>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 41)) +>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 41)) + +type _E = [T] extends [{ _E: () => infer E }] ? E : never; +>_E : Symbol(_E, Decl(nondistributiveConditionalTypeInfer.ts, 0, 68)) +>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 1, 8)) +>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 1, 8)) +>_E : Symbol(_E, Decl(nondistributiveConditionalTypeInfer.ts, 1, 27)) +>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 1, 43)) +>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 1, 43)) + +type _A = [T] extends [{ _A: () => infer A }] ? A : never; +>_A : Symbol(_A, Decl(nondistributiveConditionalTypeInfer.ts, 1, 61)) +>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 2, 8)) +>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 2, 8)) +>_A : Symbol(_A, Decl(nondistributiveConditionalTypeInfer.ts, 2, 27)) +>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 2, 43)) +>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 2, 43)) + +interface Sync { +>Sync : Symbol(Sync, Decl(nondistributiveConditionalTypeInfer.ts, 2, 61)) +>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 4, 15)) +>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 4, 17)) +>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 4, 20)) + + _R: (_: R) => void; +>_R : Symbol(Sync._R, Decl(nondistributiveConditionalTypeInfer.ts, 4, 25)) +>_ : Symbol(_, Decl(nondistributiveConditionalTypeInfer.ts, 5, 7)) +>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 4, 15)) + + _E: () => E; +>_E : Symbol(Sync._E, Decl(nondistributiveConditionalTypeInfer.ts, 5, 21)) +>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 4, 17)) + + _A: () => A; +>_A : Symbol(Sync._A, Decl(nondistributiveConditionalTypeInfer.ts, 6, 14)) +>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 4, 20)) +} + +type R = _R>; +>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 8, 1)) +>_R : Symbol(_R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 0)) +>Sync : Symbol(Sync, Decl(nondistributiveConditionalTypeInfer.ts, 2, 61)) + +type E = _E>; +>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 10, 40)) +>_E : Symbol(_E, Decl(nondistributiveConditionalTypeInfer.ts, 0, 68)) +>Sync : Symbol(Sync, Decl(nondistributiveConditionalTypeInfer.ts, 2, 61)) + +type A = _A>; +>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 11, 40)) +>_A : Symbol(_A, Decl(nondistributiveConditionalTypeInfer.ts, 1, 61)) +>Sync : Symbol(Sync, Decl(nondistributiveConditionalTypeInfer.ts, 2, 61)) + diff --git a/tests/baselines/reference/nondistributiveConditionalTypeInfer.types b/tests/baselines/reference/nondistributiveConditionalTypeInfer.types new file mode 100644 index 00000000000..ec301cfb344 --- /dev/null +++ b/tests/baselines/reference/nondistributiveConditionalTypeInfer.types @@ -0,0 +1,35 @@ +=== tests/cases/compiler/nondistributiveConditionalTypeInfer.ts === +type _R = [T] extends [{ _R: (_: infer R) => void }] ? R : never; +>_R : _R +>_R : (_: infer R) => void +>_ : R + +type _E = [T] extends [{ _E: () => infer E }] ? E : never; +>_E : _E +>_E : () => infer E + +type _A = [T] extends [{ _A: () => infer A }] ? A : never; +>_A : _A +>_A : () => infer A + +interface Sync { + _R: (_: R) => void; +>_R : (_: R) => void +>_ : R + + _E: () => E; +>_E : () => E + + _A: () => A; +>_A : () => A +} + +type R = _R>; +>R : number + +type E = _E>; +>E : string + +type A = _A>; +>A : void + diff --git a/tests/cases/compiler/nondistributiveConditionalTypeInfer.ts b/tests/cases/compiler/nondistributiveConditionalTypeInfer.ts new file mode 100644 index 00000000000..01d70af644b --- /dev/null +++ b/tests/cases/compiler/nondistributiveConditionalTypeInfer.ts @@ -0,0 +1,13 @@ +type _R = [T] extends [{ _R: (_: infer R) => void }] ? R : never; +type _E = [T] extends [{ _E: () => infer E }] ? E : never; +type _A = [T] extends [{ _A: () => infer A }] ? A : never; + +interface Sync { + _R: (_: R) => void; + _E: () => E; + _A: () => A; +} + +type R = _R>; +type E = _E>; +type A = _A>; \ No newline at end of file