-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 8482: Add Object.values and Object.entries #8538
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2b796ad
Add es2017.Object library file
3cd8b3a
Add tests and baselines
f3de1ec
Fix unittest
5184bea
Add es2017 lib flag
cc18e6a
Update baselines
fbd017d
Add tests and baselines
01b94cb
Address PR: add tests
191980e
Address PR: add tests
90264db
Merge branch 'fix8482' of https://github.com/Microsoft/TypeScript int…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 }): T[]; | ||
values(o: any): 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 }): [string, T][]; | ||
entries(o: any): [string, any][]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//// [useObjectValuesAndEntries1.ts] | ||
|
||
var o = { a: 1, b: 2 }; | ||
|
||
for (var x of Object.values(o)) { | ||
let y = x; | ||
} | ||
|
||
var entries = Object.entries(o); | ||
|
||
//// [useObjectValuesAndEntries1.js] | ||
var o = { a: 1, b: 2 }; | ||
for (var _i = 0, _a = Object.values(o); _i < _a.length; _i++) { | ||
var x = _a[_i]; | ||
var y = x; | ||
} | ||
var entries = Object.entries(o); |
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/useObjectValuesAndEntries1.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
=== tests/cases/conformance/es2017/useObjectValuesAndEntries1.ts === | ||
|
||
var o = { a: 1, b: 2 }; | ||
>o : Symbol(o, Decl(useObjectValuesAndEntries1.ts, 1, 3)) | ||
>a : Symbol(a, Decl(useObjectValuesAndEntries1.ts, 1, 9)) | ||
>b : Symbol(b, Decl(useObjectValuesAndEntries1.ts, 1, 15)) | ||
|
||
for (var x of Object.values(o)) { | ||
>x : Symbol(x, Decl(useObjectValuesAndEntries1.ts, 3, 8)) | ||
>Object.values : Symbol(ObjectConstructor.values, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) | ||
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>values : Symbol(ObjectConstructor.values, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) | ||
>o : Symbol(o, Decl(useObjectValuesAndEntries1.ts, 1, 3)) | ||
|
||
let y = x; | ||
>y : Symbol(y, Decl(useObjectValuesAndEntries1.ts, 4, 7)) | ||
>x : Symbol(x, Decl(useObjectValuesAndEntries1.ts, 3, 8)) | ||
} | ||
|
||
var entries = Object.entries(o); | ||
>entries : Symbol(entries, Decl(useObjectValuesAndEntries1.ts, 7, 3)) | ||
>Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) | ||
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) | ||
>o : Symbol(o, Decl(useObjectValuesAndEntries1.ts, 1, 3)) | ||
|
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/useObjectValuesAndEntries1.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=== tests/cases/conformance/es2017/useObjectValuesAndEntries1.ts === | ||
|
||
var o = { a: 1, b: 2 }; | ||
>o : { a: number; b: number; } | ||
>{ a: 1, b: 2 } : { a: number; b: number; } | ||
>a : number | ||
>1 : number | ||
>b : number | ||
>2 : number | ||
|
||
for (var x of Object.values(o)) { | ||
>x : number | ||
>Object.values(o) : number[] | ||
>Object.values : { <T>(o: { [s: string]: T; }): T[]; (o: any): any[]; } | ||
>Object : ObjectConstructor | ||
>values : { <T>(o: { [s: string]: T; }): T[]; (o: any): any[]; } | ||
>o : { a: number; b: number; } | ||
|
||
let y = x; | ||
>y : number | ||
>x : number | ||
} | ||
|
||
var entries = Object.entries(o); | ||
>entries : [string, number][] | ||
>Object.entries(o) : [string, number][] | ||
>Object.entries : { <T>(o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } | ||
>Object : ObjectConstructor | ||
>entries : { <T>(o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } | ||
>o : { a: number; b: number; } | ||
|
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/useObjectValuesAndEntries2.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
tests/cases/conformance/es2017/useObjectValuesAndEntries2.ts(4,22): error TS2339: Property 'values' does not exist on type 'ObjectConstructor'. | ||
tests/cases/conformance/es2017/useObjectValuesAndEntries2.ts(8,22): error TS2339: Property 'entries' does not exist on type 'ObjectConstructor'. | ||
|
||
|
||
==== tests/cases/conformance/es2017/useObjectValuesAndEntries2.ts (2 errors) ==== | ||
|
||
var o = { a: 1, b: 2 }; | ||
|
||
for (var x of Object.values(o)) { | ||
~~~~~~ | ||
!!! error TS2339: Property 'values' does not exist on type 'ObjectConstructor'. | ||
let y = x; | ||
} | ||
|
||
var entries = Object.entries(o); | ||
~~~~~~~ | ||
!!! error TS2339: Property 'entries' does not exist on type 'ObjectConstructor'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//// [useObjectValuesAndEntries2.ts] | ||
|
||
var o = { a: 1, b: 2 }; | ||
|
||
for (var x of Object.values(o)) { | ||
let y = x; | ||
} | ||
|
||
var entries = Object.entries(o); | ||
|
||
//// [useObjectValuesAndEntries2.js] | ||
var o = { a: 1, b: 2 }; | ||
for (var _i = 0, _a = Object.values(o); _i < _a.length; _i++) { | ||
var x = _a[_i]; | ||
var y = x; | ||
} | ||
var entries = Object.entries(o); |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/useObjectValuesAndEntries3.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
tests/cases/conformance/es2017/useObjectValuesAndEntries3.ts(4,22): error TS2339: Property 'values' does not exist on type 'ObjectConstructor'. | ||
tests/cases/conformance/es2017/useObjectValuesAndEntries3.ts(8,22): error TS2339: Property 'entries' does not exist on type 'ObjectConstructor'. | ||
|
||
|
||
==== tests/cases/conformance/es2017/useObjectValuesAndEntries3.ts (2 errors) ==== | ||
|
||
var o = { a: 1, b: 2 }; | ||
|
||
for (var x of Object.values(o)) { | ||
~~~~~~ | ||
!!! error TS2339: Property 'values' does not exist on type 'ObjectConstructor'. | ||
let y = x; | ||
} | ||
|
||
var entries = Object.entries(o); | ||
~~~~~~~ | ||
!!! error TS2339: Property 'entries' does not exist on type 'ObjectConstructor'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//// [useObjectValuesAndEntries3.ts] | ||
|
||
var o = { a: 1, b: 2 }; | ||
|
||
for (var x of Object.values(o)) { | ||
let y = x; | ||
} | ||
|
||
var entries = Object.entries(o); | ||
|
||
//// [useObjectValuesAndEntries3.js] | ||
var o = { a: 1, b: 2 }; | ||
for (var x of Object.values(o)) { | ||
let y = x; | ||
} | ||
var entries = Object.entries(o); |
10 changes: 10 additions & 0 deletions
10
tests/cases/conformance/es2017/useObjectValuesAndEntries1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @target: es5 | ||
// @lib: es5,es2017.object | ||
|
||
var o = { a: 1, b: 2 }; | ||
|
||
for (var x of Object.values(o)) { | ||
let y = x; | ||
} | ||
|
||
var entries = Object.entries(o); |
10 changes: 10 additions & 0 deletions
10
tests/cases/conformance/es2017/useObjectValuesAndEntries2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @target: es5 | ||
// @lib: es5 | ||
|
||
var o = { a: 1, b: 2 }; | ||
|
||
for (var x of Object.values(o)) { | ||
let y = x; | ||
} | ||
|
||
var entries = Object.entries(o); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @target: es6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! |
||
|
||
var o = { a: 1, b: 2 }; | ||
|
||
for (var x of Object.values(o)) { | ||
let y = x; | ||
} | ||
|
||
var entries = Object.entries(o); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you have an example of a mixed-type object that uses the any-based overload as well? Something like