diff --git a/src/lib/es2015.core.d.ts b/src/lib/es2015.core.d.ts index cfb300c784d74..09933b4ca7575 100644 --- a/src/lib/es2015.core.d.ts +++ b/src/lib/es2015.core.d.ts @@ -256,6 +256,10 @@ interface NumberConstructor { parseInt(string: string, radix?: number): number; } +type Key = { + [K in keyof T]: K extends string ? K : (K extends number ? string : never) +}[keyof T]; + interface ObjectConstructor { /** * Copy the values of all of the enumerable own properties from one or more source objects to a @@ -298,6 +302,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: T): Key[]; + /** * 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 308af721af625..5c31892846a17 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -129,6 +129,10 @@ interface Object { propertyIsEnumerable(v: PropertyKey): boolean; } +type Key = { + [K in keyof T]: K extends string ? K : (K extends number ? string : never) +}[keyof T]; + interface ObjectConstructor { new(value?: any): Object; (): any; @@ -235,10 +239,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: T): Key[]; } /** 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/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