Skip to content

Parameters created from tuple are treated as mutable instead of immutable, unless written as "...args"Β #53255

Open

Description

Bug Report

πŸ”Ž Search Terms

const array tuple parameter spread

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried,.

⏯ Playground Link

Playground Link

πŸ’» Code

declare function each<T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (fn: (...args: T) => any) => void;

const cases = [
    [1, '1'],
    [2, '2'],
] as const;

const eacher = each(cases);

// Error.
eacher((a, b) => {
});

// No error?
eacher((...args) => {
    const [a, b] = args;
});

πŸ™ Actual behavior

Argument of type '(a: 1 | 2, b: "1" | "2") => void' is not assignable to parameter of type '(...args: readonly [1, "1"] | readonly [2, "2"]) => any'.
  Types of parameters 'a' and 'args' are incompatible.
    Type 'readonly [1, "1"] | readonly [2, "2"]' is not assignable to type '[a: 1 | 2, b: "1" | "2"]'.
      The type 'readonly [1, "1"]' is 'readonly' and cannot be assigned to the mutable type '[a: 1 | 2, b: "1" | "2"]'.(2345)

Obviously they're not assignable, but why did we come up with [a: 1 | 2, b: "1" | "2"] and not readonly [a: 1 | 2, b: "1" | "2"]?

πŸ™‚ Expected behavior

No error, as though it had been expanded separately.

See also: DefinitelyTyped/DefinitelyTyped#64739

Activity

  1. added
    Fix Available
    on Mar 14, 2023
  2. jakebailey commented on Mar 20, 2023

    @jakebailey
    MemberAuthor

    Followup is here: #53398

  3. jakebailey commented on Mar 23, 2023

    @jakebailey
    MemberAuthor

    Fix has been reverted.

  4. removed
    Fix Available
    on May 4, 2023
  5. mProjectsCode commented on Sep 18, 2023

    @mProjectsCode

    will there ever be a fix for this issue or has it been abandoned?

  6. jakebailey commented on Sep 18, 2023

    @jakebailey
    MemberAuthor

    No, I just haven't come up with a fix for it, and have been working on other issues.

  7. added
    Fix Available
    on Sep 20, 2023
  8. removed
    Fix Available
    on Dec 14, 2023
  9. added
    Rescheduled
    on Mar 4, 2024
  10. added
    Domain: check: Type Inference
    on Oct 16, 2025
  11. added a commit that references this issue on Aug 25, 2026
    bf94d83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugDomain: check: Type InferenceRescheduled

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions