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

fix: tighten up Object.values and Object.entries types #42

Merged
merged 1 commit into from
Jul 15, 2024
Merged

Conversation

uhyo
Copy link
Owner

@uhyo uhyo commented Jul 7, 2024

closes #40

This fix tightens up Object.values and Object.entries types so that:

  • Object.values({}) returns unknown[] (previously never[])
  • Object.values({ foo: 123 }) returns unknown[] (previously number[])

To get non-unknown[] results you need to pass a value of type Record<string, T>.

const obj: Record<string, number> = { foo: 123 };

Object.values(obj) // number[]

This isn't still perfect but less unsafe than before.

@uhyo uhyo self-assigned this Jul 7, 2024
@uhyo uhyo merged commit 4348e7b into master Jul 15, 2024
1 check passed
@uhyo uhyo deleted the fix/40 branch July 15, 2024 13:24
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.

Issue when using object with Object.entries and Object.values
1 participant