Closed
Description
Bug Report
π Search Terms
Type 'string' cannot be used to index type 'T'.
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about index signature
β― Playground Link
Playground link with relevant code
π» Code
function foo<T extends Record<string | symbol, any>>(target: T, p: string | symbol) {
target[p]; // This is okay
target[p] = ""; // This errors
}
π Actual behavior
(parameter) target: T extends Record<string | symbol, any>
Type 'string' cannot be used to index type 'T'.(2536)
Type 'symbol' cannot be used to index type 'T'.(2536)
π Expected behavior
Either:
- It should work, as the getter already works
- Or at least the error message should be changed as it's misleading, indexing itself has no problem.