Closed
Description
TypeScript Version: 2.8.0-dev.20180302
Search Terms: Type cannot be used to index intersection
Type cannot be used to index
Code
interface I {a: 1}
function foo<T extends string>(o: I & Record<T, number>, k: T) {
o[k] // Type 'T' cannot be used to index type 'I & Record<T, number>'.
}
// the following work:
function foo2<T extends string>(o: Record<T, number>, k: T) {
o[k]
}
// same result, but T different:
function bar<T extends Record<string, number>>(o: I & T, k: keyof T) {
o[k]
}
Expected behavior:
No errors.
Actual behavior:
Error.
Playground Link: playground
Related Issues:
There's #18538, but that seems to be an issue with keyof
, which isn't an used here.