microsoft / microsoft/TypeScript
No error with Partial<Record<number, {}>> in object spreading
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.8.3
Search Terms: [type inference], [partial], [record], [object spreading]
Code
type Point = {
x: number
y: number
}
type Space = Partial<Record<number, Point>>
function addPointReducer(point: Point, pointId: number, prevSpace: Space): Space {
const prevPoint = prevSpace[pointId]
return {
...prevPoint,
[pointId]: point,
}
}
Expected behavior:
Should throw an error on ...prevPoint because Point doesn't equal to Space.
Actual behavior:
No error.
Related Issues:
Contributor guide
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
Start by reproducing the example in the linked TypeScript Playground using the reported TypeScript 3.8.3 behavior. Read the type-checking paths for object spreading, indexed access, and Partial<Record<number, Point>>. Done means the example consistently reports an error for spreading prevPoint, with focused regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100