Skip to content

Commit

Permalink
Fix soundness issue with Object.values and Object.entries.
Browse files Browse the repository at this point in the history
Back in November 2016, a PR (microsoft#12207) was submitted to make the types of `Object.entries` and `Object.values` generic.  This PR was reviewed and accepted, and as a note it was recommended that `Object.keys` be updated similarly.  The author then submitted a PR to update `Object.keys` (microsoft#12253) but @ahejlsberg made the [very valid point](microsoft#12253 (comment)) that this change was unsound and the PR was closed.  The author of both PRs then suggested that perhaps microsoft#12207 should be reverted, but this change never happened.

This PR tries to rectify this situation and make `Object.entries` and `Object.values` consistent with the sound behavior of `Object.keys`.  The major issue here is that this *IS* a breaking change since people may be relying on the currently unsound behavior of `Object.values` and `Object.entries`.  However, I think having TypeScript be inconsistent on this front indefinitely is not good, so at the least this PR should be merged into TS 4.x.
  • Loading branch information
MicahZoltu authored May 13, 2020
1 parent 5ef2228 commit 603c363
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/lib/es2017.object.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,13 @@ interface ObjectConstructor {
* Returns an array of values of the enumerable properties of an object
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
values<T>(o: { [s: string]: T } | ArrayLike<T>): T[];
values(o: object): unknown[]

/**
* Returns an array of values of the enumerable properties of an object
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
values(o: {}): any[];

/**
* Returns an array of key/values of the enumerable properties of an object
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
entries<T>(o: { [s: string]: T } | ArrayLike<T>): [string, T][];

/**
* Returns an array of key/values of the enumerable properties of an object
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
entries(o: {}): [string, any][];
* Returns an array of key/values of the enumerable properties of an object
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
entries(o: object): [string, unknown][]

/**
* Returns an object containing all own property descriptors of an object
Expand Down

0 comments on commit 603c363

Please sign in to comment.