From 646ec21153038b2d7cba903669b4158a5e5f7adc Mon Sep 17 00:00:00 2001 From: Eduard Rastoropov Date: Fri, 20 Jul 2018 20:12:19 +0300 Subject: [PATCH 1/2] Added type inference to Object.keys type definition. Reason: https://stackoverflow.com/questions/51446585/type-array-of-keys-of-a-particular-interface In short, with the current type of Object.keys: `keys(o: {}): string[]`, typescript does not know what the values of `o` are, so if I pass Object.keys from a parent React.Component to a child and type definition of this particular child's prop is specified as `(keyof InterfaceOfO)[]`, I get a `TypeError: Type 'string[]' is not assignable to type '("whatever" | "keys" | "of" | "o" | "are")[]. --- lib/lib.es5.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index ac73e23d9f620..d629252d640d6 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -258,7 +258,7 @@ interface ObjectConstructor { * Returns the names of the enumerable 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: {}): (keyof o)[]; } /** From 0176533cab78fdd6653336bbaee7d20d5603cd07 Mon Sep 17 00:00:00 2001 From: Eduard Rastoropov Date: Fri, 20 Jul 2018 20:48:24 +0300 Subject: [PATCH 2/2] Adjusted Object.keys definition Object.values has 2 type definitions: https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es2017.object.d.ts This commit returns the current type definition of Object.keys, adding it in addition to the proposed one in attempt to resolve the "non-successful checks" reported by the bot. --- lib/lib.es5.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index d629252d640d6..14d4746e49959 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -259,6 +259,12 @@ interface ObjectConstructor { * @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: {}): (keyof o)[]; + + /** + * Returns the names of the enumerable 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[]; } /**