microsoft / microsoft/TypeScript
Array rest of readonly tuple type incorrectly preserves readonly modifier
Open
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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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