microsoft / microsoft/TypeScript
Parameters created from tuple are treated as mutable instead of immutable, unless written as "...args"
Ouverte
@jakebailey y travaille déjà.
Depuis le 14/3/2023.
Bug
Domain: check: Type Inference
Rescheduled
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
Bug Report
🔎 Search Terms
const array tuple parameter spread
🕗 Version & Regression Information
- This is the behavior in every version I tried,.
⏯ 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: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64739
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.