Skip to content

Commit

Permalink
[fix] ES5 Object.keys only accepts an object (#27089)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb authored and RyanCavanaugh committed Apr 24, 2019
1 parent 6608349 commit d4ff58d
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/lib/es2015.core.d.ts
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/es5.d.ts
Expand Up @@ -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[];
}

/**
Expand Down
Expand Up @@ -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))

Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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();;
Expand Down
Expand Up @@ -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();;
Expand Down
Expand Up @@ -32,9 +32,9 @@ export const createService = <T>(
>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<T> & Service<T>
>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
Expand Down
Expand Up @@ -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))
Expand Down
Expand Up @@ -231,9 +231,9 @@ function objectToMap(obj: any) {
>Object.keys(obj).map(key => [key, obj[key]]) : [string, any][]
>Object.keys(obj).map : <U>(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 : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>key => [key, obj[key]] : (key: string) => [string, any]
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/literalTypeWidening.types
Expand Up @@ -391,9 +391,9 @@ export function keys<K extends string, V>(obj: Record<K, V>): 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<K, V>
}

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/recursiveTypeRelations.types
Expand Up @@ -72,9 +72,9 @@ export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNam
>Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap<S>)[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; <U>(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<S>
>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; }
>(obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap<S>)[key]; return obj; } : (obj: any, key: keyof S) => any
Expand Down
Expand Up @@ -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) }`;


0 comments on commit d4ff58d

Please sign in to comment.