We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
const a = {}
Object.keys(a).forEach(key => a[key])
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered:
When searching for object.keys I find:
object.keys
#20853, #20503, #19765, #19448, #15627, #15570, #15295, #13254, #12870, #12314.
Sorry, something went wrong.
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")[]
No branches or pull requests
Search Terms
Object.keys, index signature
Suggestion
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
Use Cases
It is ridiculous that code like
const a = {}
Object.keys(a).forEach(key => a[key])
will raise a 'has no index signature' error
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: