-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
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: DefinitelyTyped/DefinitelyTyped#64739
mProjectsCode
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone