Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jakebailey opened this issue Mar 14, 2023 · 4 comments Β· Fixed by #53258
Assignees
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@jakebailey
Copy link
Member

jakebailey commented Mar 14, 2023

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

@jakebailey
Copy link
Member Author

Followup is here: #53398

@jakebailey
Copy link
Member Author

Fix has been reverted.

@jakebailey jakebailey reopened this Mar 23, 2023
@jakebailey jakebailey removed the Fix Available A PR has been opened for this issue label May 4, 2023
@mProjectsCode
Copy link

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

@jakebailey
Copy link
Member Author

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

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Sep 20, 2023
@jakebailey jakebailey removed the Fix Available A PR has been opened for this issue label Dec 14, 2023
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
4 participants