-
Notifications
You must be signed in to change notification settings - Fork 13.1k
fix: support record in Object.keys #28899
New issue
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
fix: support record in Object.keys #28899
Conversation
bf2082e to
146ed2f
Compare
| Object.keys(record).forEach((key: K) => { | ||
| >Object.keys(record).forEach((key: K) => {}) : void | ||
| >Object.keys(record).forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void | ||
| >Object.keys(record) : string[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like this is using the right overload. Your code is only compiling because you can assign a function (i.e. (key: K) => {}) whose argument is a subset of type A to a function whose argument is A. For example, this is valid:
const abc: (def: number | string) => void = (def: number) => {}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that it was using src/lib/es5.d.ts, not lib/lib.es5.d.ts. Now it is Object.keys(record) : K[] !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the change should only be in src. lib is auto-generated from that folder.
0523e1f to
2db95f6
Compare
| >Object.keys(soFar) as (keyof SO_FAR)[] : (keyof SO_FAR)[] | ||
| >Object.keys(soFar) : string[] | ||
| >Object.keys : (o: {}) => string[] | ||
| >Object.keys(soFar) : never[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did this changed to never ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{} has no properties, so keyof will return the empty union (i.e. `never)
|
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes. |
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
'Bug' or 'help wanted' or is in the Community milestone
masterbranchjake runtestslocallyThis PR fixes an issue when
strictFunctionTypes: true. This code failed:with the error: