close
Skip to content

when merging a generic object type with new optional properties, these properties are not type checked #36637

@aquark

Description

@aquark

TypeScript Version: Nightly

Search Terms: generic spread optional property

Code

interface Test {
  readonly hi?: string[]
}

function test<T extends object>(value: T): Test {
  return { ...value, hi: true }
}

Expected behavior:
This should fail to type check.

Actual behavior:
It passes. Interestingly, changing any of the following causes it to fail:

  • Make the hi property non-optional
  • Replace T with object.

Related Issues: Not sure

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions