mattpocock / mattpocock/ts-reset
Fix the unsound parts of Object.values/Object.entries
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8.6k
- Forks
- 146
- PR merge metrics
- No merged PRs in 30d
Description
It's a great idea not to "fix" Object.keys as it is not broken, I fully support that! But you could push the reasoning further and actually fix the various broken parts of Object.values and Object.entries.
For instance it can introduce unexpected anys:
// Return type: any[] | null
const f = (x: unknown) => {
if (x) {
return Object.values(x);
}
return null;
}
// Return type: [string, any][] | null
const g = (x: unknown) => {
if (x) {
return Object.entries(x);
}
return null;
}
And it also does not respect structural typing and the possibility of having extra properties:
// Return type: number[], but x could have other properties with different types, should really be unknown[]
const h = (x: {a: number}) => Object.values(x);
// Return type: [string, number][] which is wrong in general for the same reason, should be [string, unknown][]
const i = (x: {a: number}) => Object.entries(x);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides TypeScript examples for Object.values and Object.entries; begin by locating the project's overrides and tests for these APIs. Compare behavior for unknown and structurally typed objects, using the issue's stated unknown-based return types as the completion criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100