Skip to content

Commit

Permalink
[fix] ES5 Object.keys only accepts an object
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 14, 2018
1 parent 4ff71ec commit bc43904
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 12 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
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Expand Up @@ -235,7 +235,7 @@ 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[];
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
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 bc43904

Please sign in to comment.