From d4ff58d53f6744208b5838e10a8ce7c20c55ea3b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 24 Apr 2019 10:18:31 -0700 Subject: [PATCH] [fix] ES5 Object.keys only accepts an object (#27089) --- src/lib/es2015.core.d.ts | 6 ++++++ src/lib/es5.d.ts | 4 ++-- .../reference/conditionalTypeDoesntSpinForever.symbols | 4 ++-- .../reference/conditionalTypeDoesntSpinForever.types | 4 ++-- .../contextualExpressionTypecheckingDoesntBlowStack.symbols | 4 ++-- .../contextualExpressionTypecheckingDoesntBlowStack.types | 4 ++-- ...enericIndexedAccessMethodIntersectionCanBeAccessed.types | 4 ++-- .../reference/inferFromGenericFunctionReturnTypes3.symbols | 4 ++-- .../reference/inferFromGenericFunctionReturnTypes3.types | 4 ++-- tests/baselines/reference/literalTypeWidening.types | 4 ++-- tests/baselines/reference/recursiveTypeRelations.types | 4 ++-- ...gedTemplateStringsWithOverloadResolution3_ES6.errors.txt | 2 +- 12 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/lib/es2015.core.d.ts b/src/lib/es2015.core.d.ts index cfb300c784d74..ccada2e0069c9 100644 --- a/src/lib/es2015.core.d.ts +++ b/src/lib/es2015.core.d.ts @@ -298,6 +298,12 @@ interface ObjectConstructor { */ getOwnPropertySymbols(o: any): symbol[]; + /** + * Returns the names of the enumerable string properties and methods 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. + */ + keys(o: {}): string[]; + /** * Returns true if the values are the same value, false otherwise. * @param value1 The first value. diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 79fd72ac9375c..de4a612d3919f 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -235,10 +235,10 @@ interface ObjectConstructor { isExtensible(o: any): boolean; /** - * Returns the names of the enumerable properties and methods of an object. + * Returns the names of the enumerable string properties and methods 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. */ - keys(o: {}): string[]; + keys(o: object): string[]; } /** diff --git a/tests/baselines/reference/conditionalTypeDoesntSpinForever.symbols b/tests/baselines/reference/conditionalTypeDoesntSpinForever.symbols index d21db8eb90d5f..b5dcb78015b3f 100644 --- a/tests/baselines/reference/conditionalTypeDoesntSpinForever.symbols +++ b/tests/baselines/reference/conditionalTypeDoesntSpinForever.symbols @@ -403,9 +403,9 @@ export enum PubSubRecordIsStoredInRedisAsA { fields: () => new Set(Object.keys(soFar) as (keyof SO_FAR)[]), >fields : Symbol(fields, Decl(conditionalTypeDoesntSpinForever.ts, 94, 18)) >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, --, --)) ->Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --)) +>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --)) +>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >soFar : Symbol(soFar, Decl(conditionalTypeDoesntSpinForever.ts, 92, 29)) >SO_FAR : Symbol(SO_FAR, Decl(conditionalTypeDoesntSpinForever.ts, 92, 21)) diff --git a/tests/baselines/reference/conditionalTypeDoesntSpinForever.types b/tests/baselines/reference/conditionalTypeDoesntSpinForever.types index d4fe4bf48261b..3109b19bacfaf 100644 --- a/tests/baselines/reference/conditionalTypeDoesntSpinForever.types +++ b/tests/baselines/reference/conditionalTypeDoesntSpinForever.types @@ -410,9 +410,9 @@ export enum PubSubRecordIsStoredInRedisAsA { >Set : SetConstructor >Object.keys(soFar) as (keyof SO_FAR)[] : (keyof SO_FAR)[] >Object.keys(soFar) : string[] ->Object.keys : (o: {}) => string[] +>Object.keys : { (o: object): string[]; (o: {}): string[]; } >Object : ObjectConstructor ->keys : (o: {}) => string[] +>keys : { (o: object): string[]; (o: {}): string[]; } >soFar : SO_FAR hasField: (fieldName: string | number | symbol) => fieldName in soFar diff --git a/tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.symbols b/tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.symbols index fc44c97996c92..60dfdd9983ae3 100644 --- a/tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.symbols +++ b/tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.symbols @@ -21,9 +21,9 @@ export default class Operation { for(const parameterLocation of Object.keys(parameterValues)) { >parameterLocation : Symbol(parameterLocation, Decl(contextualExpressionTypecheckingDoesntBlowStack.ts, 8, 17)) ->Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --)) +>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --)) +>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >parameterValues : Symbol(parameterValues, Decl(contextualExpressionTypecheckingDoesntBlowStack.ts, 6, 23)) const parameter: any = (this as any).getParameter();; diff --git a/tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.types b/tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.types index 8d462f4dbd912..3e690f0844b1d 100644 --- a/tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.types +++ b/tests/baselines/reference/contextualExpressionTypecheckingDoesntBlowStack.types @@ -21,9 +21,9 @@ export default class Operation { for(const parameterLocation of Object.keys(parameterValues)) { >parameterLocation : string >Object.keys(parameterValues) : string[] ->Object.keys : (o: {}) => string[] +>Object.keys : { (o: object): string[]; (o: {}): string[]; } >Object : ObjectConstructor ->keys : (o: {}) => string[] +>keys : { (o: object): string[]; (o: {}): string[]; } >parameterValues : any const parameter: any = (this as any).getParameter();; diff --git a/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.types b/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.types index d16a75912f491..f5d2f78e0f6c7 100644 --- a/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.types +++ b/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.types @@ -32,9 +32,9 @@ export const createService = ( >Object.keys(ServiceCtr).forEach(key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; }) : void >Object.keys(ServiceCtr).forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void >Object.keys(ServiceCtr) : string[] ->Object.keys : (o: {}) => string[] +>Object.keys : (o: object) => string[] >Object : ObjectConstructor ->keys : (o: {}) => string[] +>keys : (o: object) => string[] >ServiceCtr : ExtendedService & Service >forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void >key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; } : (key: string) => void diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols index 7281886e627e0..f89421cde07a7 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols @@ -204,9 +204,9 @@ function objectToMap(obj: any) { return new Map(Object.keys(obj).map(key => [key, obj[key]])); >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, --, --)) >Object.keys(obj).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) ->Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --)) +>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --)) +>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >obj : Symbol(obj, Decl(inferFromGenericFunctionReturnTypes3.ts, 83, 21)) >map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) >key : Symbol(key, Decl(inferFromGenericFunctionReturnTypes3.ts, 84, 37)) diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types index ccbeb99a11379..fd83694a171a3 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types @@ -231,9 +231,9 @@ function objectToMap(obj: any) { >Object.keys(obj).map(key => [key, obj[key]]) : [string, any][] >Object.keys(obj).map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] >Object.keys(obj) : string[] ->Object.keys : (o: {}) => string[] +>Object.keys : { (o: object): string[]; (o: {}): string[]; } >Object : ObjectConstructor ->keys : (o: {}) => string[] +>keys : { (o: object): string[]; (o: {}): string[]; } >obj : any >map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] >key => [key, obj[key]] : (key: string) => [string, any] diff --git a/tests/baselines/reference/literalTypeWidening.types b/tests/baselines/reference/literalTypeWidening.types index a96ddc8c5da3e..95bde9a08ac3d 100644 --- a/tests/baselines/reference/literalTypeWidening.types +++ b/tests/baselines/reference/literalTypeWidening.types @@ -391,9 +391,9 @@ export function keys(obj: Record): K[] { return Object.keys(obj) as K[] >Object.keys(obj) as K[] : K[] >Object.keys(obj) : string[] ->Object.keys : (o: {}) => string[] +>Object.keys : (o: object) => string[] >Object : ObjectConstructor ->keys : (o: {}) => string[] +>keys : (o: object) => string[] >obj : Record } diff --git a/tests/baselines/reference/recursiveTypeRelations.types b/tests/baselines/reference/recursiveTypeRelations.types index cb0baef7919d6..669ab3879c4fc 100644 --- a/tests/baselines/reference/recursiveTypeRelations.types +++ b/tests/baselines/reference/recursiveTypeRelations.types @@ -72,9 +72,9 @@ export function css(styles: S, ...classNam >Object.keys(arg).reduce((obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap)[key]; return obj; }, {}) : any >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; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } >Object.keys(arg) : string[] ->Object.keys : (o: {}) => string[] +>Object.keys : (o: object) => string[] >Object : ObjectConstructor ->keys : (o: {}) => string[] +>keys : (o: object) => string[] >arg : ClassNameObjectMap >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; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } >(obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap)[key]; return obj; } : (obj: any, key: keyof S) => any diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3_ES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3_ES6.errors.txt index a4ba377af29fd..c5063689b51b4 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3_ES6.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3_ES6.errors.txt @@ -89,7 +89,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio fn5 `${ (n) => n.toFixed() }`; // will error; 'n' should have type 'string'. ~~~~~~~ !!! error TS2551: Property 'toFixed' does not exist on type 'string'. Did you mean 'fixed'? -!!! related TS2728 /.ts/lib.es2015.core.d.ts:466:5: 'fixed' is declared here. +!!! related TS2728 /.ts/lib.es2015.core.d.ts:472:5: 'fixed' is declared here. fn5 `${ (n) => n.substr(0) }`; \ No newline at end of file