You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
constgetProperty=<T,PextendskeyofT>(key: P,obj: T)=>obj[key]interfaceIobj{[key: number]: any}constobj: Iobj={5: 5}getProperty(5,obj)// Error: 'Argument of type '5' is not assignable to parameter of type 'never'.'
Expected behavior:
Noerrors(tsshould infer thatkey is oftypenumberhere)
Actual behavior:
Error: 'Argument of type '5' is not assignable to parameter of type 'never'.'
The text was updated successfully, but these errors were encountered:
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
Expected behavior:
Actual behavior:
The text was updated successfully, but these errors were encountered: