microsoft / microsoft/TypeScript

Array rest of readonly tuple type incorrectly preserves readonly modifier

Open
#35,965 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.8.0-dev.20200101

Search Terms: readonly tuple rest

Code

declare const tuple: readonly [number, ...number[]];

const [a, ...rest] = tuple;
rest[0] = 1;
rest.push(2);

Expected behavior:

rest: number[]
I should be able to modify the resulting array.

Actual behavior:

rest: readonly number[]
Not able to modify the array (even though it is a mutable clone at runtime).

Playground Link: https://www.typescriptlang.org/play/?ts=3.8.0-dev.20200101&ssl=1&ssc=1&pln=5&pc=14#code/CYUwxgNghgTiAEYD2A7AzgF3hgrgBwhAC544phUIBPeAbRRwFsAjEGAGngDoeGW3aAXUEBuAFBjk6LLSiceXOJkHwAvNnyFxSjLQAMK9QEZtITFzw40ACwAUAJgCUIoA

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 with the linked TypeScript Playground reproduction using the readonly tuple rest destructuring example. Trace how the compiler infers the type of rest, then verify that the completed behavior allows rest[0] = 1 and rest.push(2) while preserving the reported runtime semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.