Skip to content

Object created by rest operator keeps readonly status #23734

@codepunkt

Description

@codepunkt

When destructuring a readonly object with the rest operator, the new object that is created keeps the readonly flag on it's properties. Rest operator creates a new object the same way that spread operator does, so i assume it should not keep any flags.

For reference:
Issues #14058 and #19178 target the same problem with spread operator and have both been fixed.

TypeScript Version: 2.8.3

Search Terms: rest readonly, destructuring readonly

Code

type ObjType = {
  foo: string
  baz: string
  quux: string
}

const obj: Readonly<ObjType> = {
  foo: 'bar',
  baz: 'qux',
  quux: 'quuz',
}

const { foo, ...rest } = obj

delete rest.baz

Expected behavior:
Successful compilation

Actual behavior:
test.ts(15,8): error TS2704: The operand of a delete operator cannot be a read-only property.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged 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