Skip to content
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

fixed types for Object.values and Object.entries #58358

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/lib/es2017.object.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ 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<T>(o: { [s: string]: T; }): T[];
values<T>(o: { [s: number]: T; }): T[];
values<T>(o: { [s: string | number]: T; }): T[];

/**
* Returns an array of values of the enumerable properties of an object
Expand All @@ -15,7 +17,9 @@ interface ObjectConstructor {
* 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][];
entries<T>(o: { [s: string]: T; }): [string, T][];
entries<T>(o: { [s: number]: T; }): [string, T][];
entries<T>(o: { [s: string | number]: T; }): [string, T][];

/**
* Returns an array of key/values of the enumerable properties of an object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const query = Object.entries(obj).map(
>query : Symbol(query, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 21, 5))
>Object.entries(obj).map( ([k, v]) => `${k}=${encodeURIComponent(v)}`).join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --))
>Object.entries(obj).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
>Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --))
>Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), 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, --, --))
>entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --))
>obj : Symbol(obj, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 16, 5))
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ const query = Object.entries(obj).map(
> : ^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
>Object.entries(obj) : [string, string][]
> : ^^^^^^^^^^^^^^^^^^
>Object.entries : { <T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][]; (o: {}): [string, any][]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^
>Object.entries : { <T>(o: { [s: string]: T; }): [string, T][]; <T_1>(o: { [s: number]: T_1; }): [string, T_1][]; <T_2>(o: { [s: string | number]: T_2; }): [string, T_2][]; (o: {}): [string, any][]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^
>Object : ObjectConstructor
> : ^^^^^^^^^^^^^^^^^
>entries : { <T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][]; (o: {}): [string, any][]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^
>entries : { <T>(o: { [s: string]: T; }): [string, T][]; <T_1>(o: { [s: number]: T_1; }): [string, T_1][]; <T_2>(o: { [s: string | number]: T_2; }): [string, T_2][]; (o: {}): [string, any][]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^
>obj : { param2?: string | undefined; param1: string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>map : <U>(callbackfn: (value: [string, string], index: number, array: [string, string][]) => U, thisArg?: any) => U[]
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/mappedTypeConstraints2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ function validate<T extends object>(obj: T, bounds: NumericBoundsOf<T>) {
for (const [key, val] of Object.entries(obj)) {
>key : Symbol(key, Decl(mappedTypeConstraints2.ts, 64, 16))
>val : Symbol(val, Decl(mappedTypeConstraints2.ts, 64, 20))
>Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --))
>Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), 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, --, --))
>entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --))
>obj : Symbol(obj, Decl(mappedTypeConstraints2.ts, 63, 36))

const boundsForKey = bounds[key as keyof NumericBoundsOf<T>];
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/mappedTypeConstraints2.types
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ function validate<T extends object>(obj: T, bounds: NumericBoundsOf<T>) {
> : ^^^
>Object.entries(obj) : [string, any][]
> : ^^^^^^^^^^^^^^^
>Object.entries : { <T_1>(o: { [s: string]: T_1; } | ArrayLike<T_1>): [string, T_1][]; (o: {}): [string, any][]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^
>Object.entries : { <T_1>(o: { [s: string]: T_1; }): [string, T_1][]; <T_2>(o: { [s: number]: T_2; }): [string, T_2][]; <T_3>(o: { [s: string | number]: T_3; }): [string, T_3][]; (o: {}): [string, any][]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^
>Object : ObjectConstructor
> : ^^^^^^^^^^^^^^^^^
>entries : { <T_1>(o: { [s: string]: T_1; } | ArrayLike<T_1>): [string, T_1][]; (o: {}): [string, any][]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^
>entries : { <T_1>(o: { [s: string]: T_1; }): [string, T_1][]; <T_2>(o: { [s: number]: T_2; }): [string, T_2][]; <T_3>(o: { [s: string | number]: T_3; }): [string, T_3][]; (o: {}): [string, any][]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^
>obj : T
> : ^

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/unionTypeInference.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ async function fun<T>(deepPromised: DeepPromised<T>) {

for (const value of Object.values(deepPromisedWithIndexer)) {
>value : Symbol(value, Decl(unionTypeInference.ts, 62, 14))
>Object.values : Symbol(ObjectConstructor.values, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --))
>Object.values : Symbol(ObjectConstructor.values, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), 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, --, --))
>values : Symbol(ObjectConstructor.values, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --))
>deepPromisedWithIndexer : Symbol(deepPromisedWithIndexer, Decl(unionTypeInference.ts, 61, 9))

const awaitedValue = await value;
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/unionTypeInference.types
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ async function fun<T>(deepPromised: DeepPromised<T>) {
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>Object.values(deepPromisedWithIndexer) : ({} | ({ [containsPromises]?: true | undefined; } & {}) | Promise<{ [containsPromises]?: true | undefined; } & {}> | null | undefined)[]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>Object.values : { <T_1>(o: { [s: string]: T_1; } | ArrayLike<T_1>): T_1[]; (o: {}): any[]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^^^^^^^^^^
>Object.values : { <T_1>(o: { [s: string]: T_1; }): T_1[]; <T_2>(o: { [s: number]: T_2; }): T_2[]; <T_3>(o: { [s: string | number]: T_3; }): T_3[]; (o: {}): any[]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^^^^^^^^^^
>Object : ObjectConstructor
> : ^^^^^^^^^^^^^^^^^
>values : { <T_1>(o: { [s: string]: T_1; } | ArrayLike<T_1>): T_1[]; (o: {}): any[]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^^^^^^^^^^
>values : { <T_1>(o: { [s: string]: T_1; }): T_1[]; <T_2>(o: { [s: number]: T_2; }): T_2[]; <T_3>(o: { [s: string | number]: T_3; }): T_3[]; (o: {}): any[]; }
> : ^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^^^^^^^^^^
>deepPromisedWithIndexer : DeepPromised<{ [name: string]: {} | null | undefined; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down