diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8305443a19bac..5814b2dcfbf42 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20192,7 +20192,7 @@ namespace ts { markAliasReferenced(parentSymbol, node); } if (!prop) { - const indexInfo = assignmentKind === AssignmentKind.None || !isGenericObjectType(leftType) ? getIndexInfoOfType(apparentType, IndexKind.String) : undefined; + const indexInfo = assignmentKind === AssignmentKind.None || !isGenericObjectType(leftType) || isThisTypeParameter(leftType) ? getIndexInfoOfType(apparentType, IndexKind.String) : undefined; if (!(indexInfo && indexInfo.type)) { if (isJSLiteralType(leftType)) { return anyType; diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt index 40ccd13dac4eb..fffeac41ff7b5 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt @@ -222,11 +222,12 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23 let y: ReadonlyArray[K] = 'abc'; } - // Repro from #31439 + // Repro from #31439 and #31691 export class c { [x: string]: string; constructor() { + this.a = "b"; this["a"] = "b"; } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.js b/tests/baselines/reference/keyofAndIndexedAccess2.js index 7547a3f84c593..91cf2c89ff24b 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.js +++ b/tests/baselines/reference/keyofAndIndexedAccess2.js @@ -137,11 +137,12 @@ function fn4() { let y: ReadonlyArray[K] = 'abc'; } -// Repro from #31439 +// Repro from #31439 and #31691 export class c { [x: string]: string; constructor() { + this.a = "b"; this["a"] = "b"; } } @@ -245,9 +246,10 @@ function fn4() { let x = 'abc'; let y = 'abc'; } -// Repro from #31439 +// Repro from #31439 and #31691 export class c { constructor() { + this.a = "b"; this["a"] = "b"; } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.symbols b/tests/baselines/reference/keyofAndIndexedAccess2.symbols index 91602f93e1d85..4a7721ff801a0 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess2.symbols @@ -503,7 +503,7 @@ function fn4() { >K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 133, 13)) } -// Repro from #31439 +// Repro from #31439 and #31691 export class c { >c : Symbol(c, Decl(keyofAndIndexedAccess2.ts, 136, 1)) @@ -512,6 +512,9 @@ export class c { >x : Symbol(x, Decl(keyofAndIndexedAccess2.ts, 141, 3)) constructor() { + this.a = "b"; +>this : Symbol(c, Decl(keyofAndIndexedAccess2.ts, 136, 1)) + this["a"] = "b"; >this : Symbol(c, Decl(keyofAndIndexedAccess2.ts, 136, 1)) } @@ -520,44 +523,44 @@ export class c { // Repro from #31385 type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; ->Foo : Symbol(Foo, Decl(keyofAndIndexedAccess2.ts, 145, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 149, 9)) ->key : Symbol(key, Decl(keyofAndIndexedAccess2.ts, 149, 17)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 149, 34)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 149, 9)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 149, 34)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 149, 9)) +>Foo : Symbol(Foo, Decl(keyofAndIndexedAccess2.ts, 146, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 150, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess2.ts, 150, 17)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 150, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 150, 9)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 150, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 150, 9)) type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; ->Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 149, 64)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 151, 9)) ->key : Symbol(key, Decl(keyofAndIndexedAccess2.ts, 151, 17)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 151, 34)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 151, 9)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 151, 34)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 151, 9)) +>Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 150, 64)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 152, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess2.ts, 152, 17)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 152, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 152, 9)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 152, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 152, 9)) type Baz> = { [K in keyof Q]: T[Q[K]] }; ->Baz : Symbol(Baz, Decl(keyofAndIndexedAccess2.ts, 151, 66)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 153, 9)) ->Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 153, 11)) ->Foo : Symbol(Foo, Decl(keyofAndIndexedAccess2.ts, 145, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 153, 9)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 153, 35)) ->Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 153, 11)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 153, 9)) ->Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 153, 11)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 153, 35)) +>Baz : Symbol(Baz, Decl(keyofAndIndexedAccess2.ts, 152, 66)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 154, 9)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 154, 11)) +>Foo : Symbol(Foo, Decl(keyofAndIndexedAccess2.ts, 146, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 154, 9)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 154, 35)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 154, 11)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 154, 9)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 154, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 154, 35)) type Qux> = { [K in keyof Q]: T[Q[K]["0"]] }; ->Qux : Symbol(Qux, Decl(keyofAndIndexedAccess2.ts, 153, 60)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 155, 9)) ->Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 155, 11)) ->Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 149, 64)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 155, 9)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 155, 35)) ->Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 155, 11)) ->T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 155, 9)) ->Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 155, 11)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 155, 35)) +>Qux : Symbol(Qux, Decl(keyofAndIndexedAccess2.ts, 154, 60)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 156, 9)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 156, 11)) +>Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 150, 64)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 156, 9)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 156, 35)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 156, 11)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 156, 9)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 156, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 156, 35)) diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.types b/tests/baselines/reference/keyofAndIndexedAccess2.types index 45cf1d4bad5d4..a6d8315466562 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.types +++ b/tests/baselines/reference/keyofAndIndexedAccess2.types @@ -499,7 +499,7 @@ function fn4() { >'abc' : "abc" } -// Repro from #31439 +// Repro from #31439 and #31691 export class c { >c : c @@ -508,6 +508,13 @@ export class c { >x : string constructor() { + this.a = "b"; +>this.a = "b" : "b" +>this.a : string +>this : this +>a : string +>"b" : "b" + this["a"] = "b"; >this["a"] = "b" : "b" >this["a"] : string diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts index 898648cea44fe..b242aa3de60bc 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts @@ -139,11 +139,12 @@ function fn4() { let y: ReadonlyArray[K] = 'abc'; } -// Repro from #31439 +// Repro from #31439 and #31691 export class c { [x: string]: string; constructor() { + this.a = "b"; this["a"] = "b"; } }