Skip to content

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

@Rendalf

Description

@Rendalf

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InvestigationThis issue needs a team member to investigate its status.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions