Closed
Description
keyof
works for dynamic properties where keys are strings (although not quite as expected) but not so much with numbers.
TypeScript Version: 2.2.1
Code
const getProperty = <T, P extends keyof T>(key: P, obj: T) => obj[key]
interface Iobj {
[key: number]: any
}
const obj: Iobj = {5: 5}
getProperty(5, obj) // Error: 'Argument of type '5' is not assignable to parameter of type 'never'.'
Expected behavior:
No errors (ts should infer that key is of type number here)
Actual behavior:
Error: 'Argument of type '5' is not assignable to parameter of type 'never'.'