diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt index cba7ab52469..68669463d95 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -66,9 +66,10 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(123,5): error tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(140,5): error TS2322: Type '42' is not assignable to type 'T[K]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(141,5): error TS2322: Type '"hello"' is not assignable to type 'T[K]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error TS2322: Type 'number[]' is not assignable to type 'T[K]'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(158,9): error TS2322: Type '"hello"' is not assignable to type 'Record[K]'. -==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (41 errors) ==== +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (42 errors) ==== class Shape { name: string; width: number; @@ -321,4 +322,22 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error ~~~~ !!! error TS2322: Type 'number[]' is not assignable to type 'T[K]'. } + + // Repro from #28839 + + function f30() { + let x: Partial>[K] = "hello"; + } + + // We simplify indexed accesses applied to mapped types up to five levels deep + + function f31() { + let x: Partial>>>>[K] = "hello"; + } + + function f32() { + let x: Partial>>>>>[K] = "hello"; + ~ +!!! error TS2322: Type '"hello"' is not assignable to type 'Record[K]'. + } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js index 88a1b74f14d..0cf77e79ba6 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.js +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -142,6 +142,22 @@ function test1, K extends keyof T>(t: T, k: K) { t[k] = "hello"; // Error t[k] = [10, 20]; // Error } + +// Repro from #28839 + +function f30() { + let x: Partial>[K] = "hello"; +} + +// We simplify indexed accesses applied to mapped types up to five levels deep + +function f31() { + let x: Partial>>>>[K] = "hello"; +} + +function f32() { + let x: Partial>>>>>[K] = "hello"; +} //// [keyofAndIndexedAccessErrors.js] @@ -215,3 +231,14 @@ function test1(t, k) { t[k] = "hello"; // Error t[k] = [10, 20]; // Error } +// Repro from #28839 +function f30() { + var x = "hello"; +} +// We simplify indexed accesses applied to mapped types up to five levels deep +function f31() { + var x = "hello"; +} +function f32() { + var x = "hello"; +} diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols index df1707849cb..3f32679a813 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols @@ -486,3 +486,56 @@ function test1, K extends keyof T>(t: T, k: K) { >k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 138, 70)) } +// Repro from #28839 + +function f30() { +>f30 : Symbol(f30, Decl(keyofAndIndexedAccessErrors.ts, 142, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 146, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 146, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 146, 13)) + + let x: Partial>[K] = "hello"; +>x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 147, 7)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 146, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 146, 15)) +} + +// We simplify indexed accesses applied to mapped types up to five levels deep + +function f31() { +>f31 : Symbol(f31, Decl(keyofAndIndexedAccessErrors.ts, 148, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 152, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) + + let x: Partial>>>>[K] = "hello"; +>x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 153, 7)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 152, 15)) +} + +function f32() { +>f32 : Symbol(f32, Decl(keyofAndIndexedAccessErrors.ts, 154, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 156, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) + + let x: Partial>>>>>[K] = "hello"; +>x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 157, 7)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 156, 15)) +} + diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index 68dc361c99e..b9d17df0341 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -465,3 +465,31 @@ function test1, K extends keyof T>(t: T, k: K) { >20 : 20 } +// Repro from #28839 + +function f30() { +>f30 : () => void + + let x: Partial>[K] = "hello"; +>x : Partial>[K] +>"hello" : "hello" +} + +// We simplify indexed accesses applied to mapped types up to five levels deep + +function f31() { +>f31 : () => void + + let x: Partial>>>>[K] = "hello"; +>x : Partial>>>>[K] +>"hello" : "hello" +} + +function f32() { +>f32 : () => void + + let x: Partial>>>>>[K] = "hello"; +>x : Partial>>>>>[K] +>"hello" : "hello" +} +