microsoft / microsoft/TypeScript

No error with Partial<Record<number, {}>> in object spreading

Open
#37,337 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Investigation
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.

Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=17&pc=1#code/C4TwDgpgBACg9gSwHbCgXigbwFBSgDwC4okBXAWwCMIAnXKEYsq27AX221EigGUwAhgGNoGGAJrAEAgDYAeAEoQhcGgBM5zajQA0sRCgB8hztgBmpJEKlwkUAWrXxkwJWtIiaACjAHgxZxQ9XxcASTUmCm1gmggAN35hCGJEkQBKFMERLHoVJABnVDBYuMDUDGL41IgAbRCUcIBdTjxY4FIaOxw8PAA6fsrSvx16PDq-JuJ64BG8Dg4gA

Related Issues:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.