Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added type inference to Object.keys type definition. #25832

Closed
wants to merge 2 commits into from

Conversation

LAITONEN
Copy link

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")[].

Fixes #

LAITONEN added 2 commits July 20, 2018 20:12
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")[].
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.
@j-oliveras
Copy link
Contributor

See #12870, #13971, #24243 and others (search object.keys).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants