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

More precise Object.entries type declarations #12207

Merged
merged 1 commit into from
Nov 14, 2016

Conversation

ethanresnick
Copy link
Contributor

Uses the new index type queries and indexed access types from #11929 to get better type inference for Object.entries.

Before:

Object.entries({a: 1, b: 2}) // [string, number][]
Object.entries({a: true, b: 2}) // [string, number | boolean][]
Object.entries("foo") // [string, any][]

After:

Object.entries({a: 1, b: 2}) // ['a' | 'b', number][]
Object.entries({a: true, b: 2}) // ['a' | 'b', number | boolean][]
Object.entries("foo") // [string, any][]

One edge case is Object.entries({}). Before, that was inferred as [string, {}][]; with this change it'd be [never, any][]. That might be a problem, although I don't think it is, since never is assignable to string.

We can leverage the new index type queries and indexed access types
from microsoft#11929 to get better type inference for Object.entries.
@msftclas
Copy link

Hi @ethanresnick, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, MSBOT;

@mhegazy mhegazy merged commit 2827b37 into microsoft:master Nov 14, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Nov 14, 2016

since you made that change, object.keys seems like another place we can make a similar change.

ethanresnick added a commit to ethanresnick/TypeScript that referenced this pull request Nov 15, 2016
Applying the same logic used on Object.entries in the prior commit and
in microsoft#12207
ethanresnick added a commit to ethanresnick/TypeScript that referenced this pull request Nov 15, 2016
Applying the same logic used on Object.entries in the prior commit and
in microsoft#12207
mhegazy added a commit that referenced this pull request Nov 29, 2016
mhegazy added a commit that referenced this pull request Nov 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants