Object.keys, index signature
Currently the definition of Object.keys in lib.d.ts is
keys(o: {}): string[];
why not change to
keys<T extends Object>(o: T): Array<keyof T>
and accordingly change for ... in loop
It is ridiculous that code like
const a = {}
Object.keys(a).forEach(key => a[key])
will raise a 'has no index signature' error
My suggestion meets these guidelines:
When searching for object.keys I find:
Yep, that works out of the box:
const getKeys = <T extends {}>(o: T): Array<keyof T> => <Array<keyof T>>Object.keys(o)
var keys = getKeys({ first: "John", last: "Lennon" }) // => ("first" | "last")[]
Most helpful comment
Yep, that works out of the box: