diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 840aa5e827b..ecac36fafdc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13506,7 +13506,7 @@ namespace ts { function getImpliedConstraint(type: Type, checkNode: TypeNode, extendsNode: TypeNode): Type | undefined { return isUnaryTupleTypeNode(checkNode) && isUnaryTupleTypeNode(extendsNode) ? getImpliedConstraint(type, (checkNode as TupleTypeNode).elements[0], (extendsNode as TupleTypeNode).elements[0]) : - getActualTypeVariable(getTypeFromTypeNode(checkNode)) === type ? getTypeFromTypeNode(extendsNode) : + getActualTypeVariable(getTypeFromTypeNode(checkNode)) === getActualTypeVariable(type) ? getTypeFromTypeNode(extendsNode) : undefined; } diff --git a/tests/baselines/reference/substitutionTypeForIndexedAccessType1.js b/tests/baselines/reference/substitutionTypeForIndexedAccessType1.js new file mode 100644 index 00000000000..21e18fc1e07 --- /dev/null +++ b/tests/baselines/reference/substitutionTypeForIndexedAccessType1.js @@ -0,0 +1,8 @@ +//// [substitutionTypeForIndexedAccessType1.ts] +type AddPropToObject = Prop extends keyof Obj + ? Obj[Prop] extends unknown[] + ? [...Obj[Prop]] + : never + : never + +//// [substitutionTypeForIndexedAccessType1.js] diff --git a/tests/baselines/reference/substitutionTypeForIndexedAccessType1.symbols b/tests/baselines/reference/substitutionTypeForIndexedAccessType1.symbols new file mode 100644 index 00000000000..6b46ff33c16 --- /dev/null +++ b/tests/baselines/reference/substitutionTypeForIndexedAccessType1.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/substitutionTypeForIndexedAccessType1.ts === +type AddPropToObject = Prop extends keyof Obj +>AddPropToObject : Symbol(AddPropToObject, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 0)) +>Obj : Symbol(Obj, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 21)) +>Prop : Symbol(Prop, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 40)) +>Prop : Symbol(Prop, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 40)) +>Obj : Symbol(Obj, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 21)) + + ? Obj[Prop] extends unknown[] +>Obj : Symbol(Obj, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 21)) +>Prop : Symbol(Prop, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 40)) + + ? [...Obj[Prop]] +>Obj : Symbol(Obj, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 21)) +>Prop : Symbol(Prop, Decl(substitutionTypeForIndexedAccessType1.ts, 0, 40)) + + : never + : never diff --git a/tests/baselines/reference/substitutionTypeForIndexedAccessType1.types b/tests/baselines/reference/substitutionTypeForIndexedAccessType1.types new file mode 100644 index 00000000000..8b9a2ef6ba3 --- /dev/null +++ b/tests/baselines/reference/substitutionTypeForIndexedAccessType1.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/substitutionTypeForIndexedAccessType1.ts === +type AddPropToObject = Prop extends keyof Obj +>AddPropToObject : AddPropToObject + + ? Obj[Prop] extends unknown[] + ? [...Obj[Prop]] + : never + : never diff --git a/tests/baselines/reference/substitutionTypeForIndexedAccessType2.js b/tests/baselines/reference/substitutionTypeForIndexedAccessType2.js new file mode 100644 index 00000000000..9cad4206654 --- /dev/null +++ b/tests/baselines/reference/substitutionTypeForIndexedAccessType2.js @@ -0,0 +1,18 @@ +//// [substitutionTypeForIndexedAccessType2.ts] +interface Foo { + foo: string|undefined +} + +type Str = T + +type Bar = + T extends Foo + ? T['foo'] extends string + // Type 'T["foo"]' does not satisfy the constraint 'string'. + // Type 'string | undefined' is not assignable to type 'string'. + // Type 'undefined' is not assignable to type 'string'.(2344) + ? Str + : never + : never + +//// [substitutionTypeForIndexedAccessType2.js] diff --git a/tests/baselines/reference/substitutionTypeForIndexedAccessType2.symbols b/tests/baselines/reference/substitutionTypeForIndexedAccessType2.symbols new file mode 100644 index 00000000000..db31bbe9c55 --- /dev/null +++ b/tests/baselines/reference/substitutionTypeForIndexedAccessType2.symbols @@ -0,0 +1,33 @@ +=== tests/cases/compiler/substitutionTypeForIndexedAccessType2.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(substitutionTypeForIndexedAccessType2.ts, 0, 0)) + + foo: string|undefined +>foo : Symbol(Foo.foo, Decl(substitutionTypeForIndexedAccessType2.ts, 0, 15)) +} + +type Str = T +>Str : Symbol(Str, Decl(substitutionTypeForIndexedAccessType2.ts, 2, 1)) +>T : Symbol(T, Decl(substitutionTypeForIndexedAccessType2.ts, 4, 9)) +>T : Symbol(T, Decl(substitutionTypeForIndexedAccessType2.ts, 4, 9)) + +type Bar = +>Bar : Symbol(Bar, Decl(substitutionTypeForIndexedAccessType2.ts, 4, 30)) +>T : Symbol(T, Decl(substitutionTypeForIndexedAccessType2.ts, 6, 9)) + + T extends Foo +>T : Symbol(T, Decl(substitutionTypeForIndexedAccessType2.ts, 6, 9)) +>Foo : Symbol(Foo, Decl(substitutionTypeForIndexedAccessType2.ts, 0, 0)) + + ? T['foo'] extends string +>T : Symbol(T, Decl(substitutionTypeForIndexedAccessType2.ts, 6, 9)) + + // Type 'T["foo"]' does not satisfy the constraint 'string'. + // Type 'string | undefined' is not assignable to type 'string'. + // Type 'undefined' is not assignable to type 'string'.(2344) + ? Str +>Str : Symbol(Str, Decl(substitutionTypeForIndexedAccessType2.ts, 2, 1)) +>T : Symbol(T, Decl(substitutionTypeForIndexedAccessType2.ts, 6, 9)) + + : never + : never diff --git a/tests/baselines/reference/substitutionTypeForIndexedAccessType2.types b/tests/baselines/reference/substitutionTypeForIndexedAccessType2.types new file mode 100644 index 00000000000..2ded8fe41a4 --- /dev/null +++ b/tests/baselines/reference/substitutionTypeForIndexedAccessType2.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/substitutionTypeForIndexedAccessType2.ts === +interface Foo { + foo: string|undefined +>foo : string +} + +type Str = T +>Str : T + +type Bar = +>Bar : Bar + + T extends Foo + ? T['foo'] extends string + // Type 'T["foo"]' does not satisfy the constraint 'string'. + // Type 'string | undefined' is not assignable to type 'string'. + // Type 'undefined' is not assignable to type 'string'.(2344) + ? Str + : never + : never diff --git a/tests/cases/compiler/substitutionTypeForIndexedAccessType1.ts b/tests/cases/compiler/substitutionTypeForIndexedAccessType1.ts new file mode 100644 index 00000000000..4c665d76854 --- /dev/null +++ b/tests/cases/compiler/substitutionTypeForIndexedAccessType1.ts @@ -0,0 +1,5 @@ +type AddPropToObject = Prop extends keyof Obj + ? Obj[Prop] extends unknown[] + ? [...Obj[Prop]] + : never + : never \ No newline at end of file diff --git a/tests/cases/compiler/substitutionTypeForIndexedAccessType2.ts b/tests/cases/compiler/substitutionTypeForIndexedAccessType2.ts new file mode 100644 index 00000000000..c687879efd4 --- /dev/null +++ b/tests/cases/compiler/substitutionTypeForIndexedAccessType2.ts @@ -0,0 +1,15 @@ +interface Foo { + foo: string|undefined +} + +type Str = T + +type Bar = + T extends Foo + ? T['foo'] extends string + // Type 'T["foo"]' does not satisfy the constraint 'string'. + // Type 'string | undefined' is not assignable to type 'string'. + // Type 'undefined' is not assignable to type 'string'.(2344) + ? Str + : never + : never \ No newline at end of file