Closed
Description
Bug Report
Reading from a two level deep Indexed Access type works, but writing gives "Type cannot be used to index".
🔎 Search Terms
- Indexed Access
- Mapped Type
🕗 Version & Regression Information
- This changed between versions 3.3.3 and 3.5.1
⏯ Playground Link
Playground link with relevant code
💻 Code
enum A {
First = "1",
Second = "2"
}
type Values = { [a in A]: { [b: string]: string }}
const values: Values = {} as any;
function test<T extends A>(a: T, b: string) {
const valueA = values[a];
values[a] = valueA;
const valueB = values[a][b]; // indexing Values[T] with string works
values[a][b] = valueB; // => Type 'string' cannot be used to index type 'Values[T]'
}
🙁 Actual behavior
Indexing a type while reading works, while writing fails with the same indexer.
🙂 Expected behavior
Indexed reads and writes both work when using the same indexer.