immerjs / immerjs/immer

WritableDraft flattens variadic tuples into plain arrays, losing tuple structure

Open
#1,230 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
881
PR merge metrics
No merged PRs in 30d

Description

🐛 Bug Report

after 11.0.0 -> 11.1.4 bump, typescript types changed, build is not passing

To Reproduce

import {produce} from "immer"

interface State {
    foo: [boolean, ...number[]];
}

produce<State>(x => foo(x));

const foo = (x: State) => x;

Observed behavior

Argument of type 'WritableNonArrayDraft<State>' is not assignable to parameter of type 'State'.
  Types of property 'foo' are incompatible.
    Type '(number | boolean)[]' is not assignable to type '[boolean, ...number[]]'.

Expected behavior

should work as in 11.0.0, seems like a slightly breaking change

Environment

  • Immer version:
  • I filed this report against the latest version of Immer

Contributor guide

No contributing guide indexed for this repository

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 TypeScript reproduction using produce and inspect the WritableNonArrayDraft type involved in the error. Compare the type behavior between Immer 11.0.0 and 11.1.4; done means the variadic tuple remains [boolean, ...number[]] and the shown build error no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.