Skip to content

Commit d4ff58d

Browse files
ljharbRyanCavanaugh
authored andcommitted
[fix] ES5 Object.keys only accepts an object (#27089)
1 parent 6608349 commit d4ff58d

12 files changed

+27
-21
lines changed

src/lib/es2015.core.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ interface ObjectConstructor {
298298
*/
299299
getOwnPropertySymbols(o: any): symbol[];
300300

301+
/**
302+
* Returns the names of the enumerable string properties and methods of an object.
303+
* @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.
304+
*/
305+
keys(o: {}): string[];
306+
301307
/**
302308
* Returns true if the values are the same value, false otherwise.
303309
* @param value1 The first value.

src/lib/es5.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ interface ObjectConstructor {
235235
isExtensible(o: any): boolean;
236236

237237
/**
238-
* Returns the names of the enumerable properties and methods of an object.
238+
* Returns the names of the enumerable string properties and methods of an object.
239239
* @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.
240240
*/
241-
keys(o: {}): string[];
241+
keys(o: object): string[];
242242
}
243243

244244
/**

tests/baselines/reference/conditionalTypeDoesntSpinForever.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ export enum PubSubRecordIsStoredInRedisAsA {
403403
fields: () => new Set(Object.keys(soFar) as (keyof SO_FAR)[]),
404404
>fields : Symbol(fields, Decl(conditionalTypeDoesntSpinForever.ts, 94, 18))
405405
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
406-
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
406+
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
407407
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
408-
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
408+
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
409409
>soFar : Symbol(soFar, Decl(conditionalTypeDoesntSpinForever.ts, 92, 29))
410410
>SO_FAR : Symbol(SO_FAR, Decl(conditionalTypeDoesntSpinForever.ts, 92, 21))
411411

tests/baselines/reference/conditionalTypeDoesntSpinForever.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ export enum PubSubRecordIsStoredInRedisAsA {
410410
>Set : SetConstructor
411411
>Object.keys(soFar) as (keyof SO_FAR)[] : (keyof SO_FAR)[]
412412
>Object.keys(soFar) : string[]
413-
>Object.keys : (o: {}) => string[]
413+
>Object.keys : { (o: object): string[]; (o: {}): string[]; }
414414
>Object : ObjectConstructor
415-
>keys : (o: {}) => string[]
415+
>keys : { (o: object): string[]; (o: {}): string[]; }
416416
>soFar : SO_FAR
417417

418418
hasField: (fieldName: string | number | symbol) => fieldName in soFar

tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export default class Operation {
2121

2222
for(const parameterLocation of Object.keys(parameterValues)) {
2323
>parameterLocation : Symbol(parameterLocation, Decl(contextualExpressionTypecheckingDoesntBlowStack.ts, 8, 17))
24-
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
24+
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
2525
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
26-
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
26+
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
2727
>parameterValues : Symbol(parameterValues, Decl(contextualExpressionTypecheckingDoesntBlowStack.ts, 6, 23))
2828

2929
const parameter: any = (this as any).getParameter();;

tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export default class Operation {
2121
for(const parameterLocation of Object.keys(parameterValues)) {
2222
>parameterLocation : string
2323
>Object.keys(parameterValues) : string[]
24-
>Object.keys : (o: {}) => string[]
24+
>Object.keys : { (o: object): string[]; (o: {}): string[]; }
2525
>Object : ObjectConstructor
26-
>keys : (o: {}) => string[]
26+
>keys : { (o: object): string[]; (o: {}): string[]; }
2727
>parameterValues : any
2828

2929
const parameter: any = (this as any).getParameter();;

tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export const createService = <T>(
3232
>Object.keys(ServiceCtr).forEach(key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; }) : void
3333
>Object.keys(ServiceCtr).forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void
3434
>Object.keys(ServiceCtr) : string[]
35-
>Object.keys : (o: {}) => string[]
35+
>Object.keys : (o: object) => string[]
3636
>Object : ObjectConstructor
37-
>keys : (o: {}) => string[]
37+
>keys : (o: object) => string[]
3838
>ServiceCtr : ExtendedService<T> & Service<T>
3939
>forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void
4040
>key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; } : (key: string) => void

tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ function objectToMap(obj: any) {
204204
return new Map(Object.keys(obj).map(key => [key, obj[key]]));
205205
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
206206
>Object.keys(obj).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
207-
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
207+
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
208208
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
209-
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
209+
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
210210
>obj : Symbol(obj, Decl(inferFromGenericFunctionReturnTypes3.ts, 83, 21))
211211
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
212212
>key : Symbol(key, Decl(inferFromGenericFunctionReturnTypes3.ts, 84, 37))

tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ function objectToMap(obj: any) {
231231
>Object.keys(obj).map(key => [key, obj[key]]) : [string, any][]
232232
>Object.keys(obj).map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
233233
>Object.keys(obj) : string[]
234-
>Object.keys : (o: {}) => string[]
234+
>Object.keys : { (o: object): string[]; (o: {}): string[]; }
235235
>Object : ObjectConstructor
236-
>keys : (o: {}) => string[]
236+
>keys : { (o: object): string[]; (o: {}): string[]; }
237237
>obj : any
238238
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
239239
>key => [key, obj[key]] : (key: string) => [string, any]

tests/baselines/reference/literalTypeWidening.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ export function keys<K extends string, V>(obj: Record<K, V>): K[] {
391391
return Object.keys(obj) as K[]
392392
>Object.keys(obj) as K[] : K[]
393393
>Object.keys(obj) : string[]
394-
>Object.keys : (o: {}) => string[]
394+
>Object.keys : (o: object) => string[]
395395
>Object : ObjectConstructor
396-
>keys : (o: {}) => string[]
396+
>keys : (o: object) => string[]
397397
>obj : Record<K, V>
398398
}
399399

tests/baselines/reference/recursiveTypeRelations.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNam
7272
>Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap<S>)[key]; return obj; }, {}) : any
7373
>Object.keys(arg).reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }
7474
>Object.keys(arg) : string[]
75-
>Object.keys : (o: {}) => string[]
75+
>Object.keys : (o: object) => string[]
7676
>Object : ObjectConstructor
77-
>keys : (o: {}) => string[]
77+
>keys : (o: object) => string[]
7878
>arg : ClassNameObjectMap<S>
7979
>reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }
8080
>(obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap<S>)[key]; return obj; } : (obj: any, key: keyof S) => any

tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3_ES6.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio
8989
fn5 `${ (n) => n.toFixed() }`; // will error; 'n' should have type 'string'.
9090
~~~~~~~
9191
!!! error TS2551: Property 'toFixed' does not exist on type 'string'. Did you mean 'fixed'?
92-
!!! related TS2728 /.ts/lib.es2015.core.d.ts:466:5: 'fixed' is declared here.
92+
!!! related TS2728 /.ts/lib.es2015.core.d.ts:472:5: 'fixed' is declared here.
9393
fn5 `${ (n) => n.substr(0) }`;
9494

9595

0 commit comments

Comments
 (0)