Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.8k
Fix 8482: Add Object.values and Object.entries #8538
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2b796ad3cd8b3af3de1ec5184beacc18e6afbd017d01b94cb191980e90264dbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /// <reference path="lib.es2016.d.ts" /> | ||
| /// <reference path="lib.es2017.object.d.ts" /> |
| 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][]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //// [useObjectValuesAndEntries1.ts] | ||
| var o = { a: 1, b: 2 }; | ||
| for (var x of Object.values(o)) { | ||
| let y = x; | ||
| } | ||
| var entries = Object.entries(o); | ||
| var entries1 = Object.entries(1); // <-- entries: [string, any][] | ||
| //// [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); | ||
| var entries1 = Object.entries(1); // <-- entries: [string, any][] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| === 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)) | ||
| var entries1 = Object.entries(1); // <-- entries: [string, any][] | ||
| >entries1 : Symbol(entries1, Decl(useObjectValuesAndEntries1.ts, 8, 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, --, --)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| === 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; } | ||
| var entries1 = Object.entries(1); // <-- entries: [string, any][] | ||
| >entries1 : [string, any][] | ||
| >Object.entries(1) : [string, any][] | ||
| >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][]; } | ||
| >1 : number | ||
| 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'. |
| 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); |
| 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'. |
| 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| //// [useObjectValuesAndEntries4.ts] | ||
| var o = { a: 1, b: 2 }; | ||
| for (var x of Object.values(o)) { | ||
| let y = x; | ||
| } | ||
| var entries = Object.entries(o); | ||
| //// [useObjectValuesAndEntries4.js] | ||
| var o = { a: 1, b: 2 }; | ||
| for (var x of Object.values(o)) { | ||
| let y = x; | ||
| } | ||
| var entries = Object.entries(o); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| === tests/cases/conformance/es2017/useObjectValuesAndEntries4.ts === | ||
| var o = { a: 1, b: 2 }; | ||
| >o : Symbol(o, Decl(useObjectValuesAndEntries4.ts, 1, 3)) | ||
| >a : Symbol(a, Decl(useObjectValuesAndEntries4.ts, 1, 9)) | ||
| >b : Symbol(b, Decl(useObjectValuesAndEntries4.ts, 1, 15)) | ||
| for (var x of Object.values(o)) { | ||
| >x : Symbol(x, Decl(useObjectValuesAndEntries4.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, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >values : Symbol(ObjectConstructor.values, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) | ||
| >o : Symbol(o, Decl(useObjectValuesAndEntries4.ts, 1, 3)) | ||
| let y = x; | ||
| >y : Symbol(y, Decl(useObjectValuesAndEntries4.ts, 4, 7)) | ||
| >x : Symbol(x, Decl(useObjectValuesAndEntries4.ts, 3, 8)) | ||
| } | ||
| var entries = Object.entries(o); | ||
| >entries : Symbol(entries, Decl(useObjectValuesAndEntries4.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, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) | ||
| >o : Symbol(o, Decl(useObjectValuesAndEntries4.ts, 1, 3)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| === tests/cases/conformance/es2017/useObjectValuesAndEntries4.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; } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // @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); | ||
| var entries1 = Object.entries(1); // <-- entries: [string, any][] | ||
| 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // @target: es6 | ||
Member 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.
ContributorAuthor 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); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // @target: es6 | ||
| // @lib: es2017 | ||
| var o = { a: 1, b: 2 }; | ||
| for (var x of Object.values(o)) { | ||
| let y = x; | ||
| } | ||
| var entries = Object.entries(o); |
Uh oh!
There was an error while loading. Please reload this page.
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