-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Union tuple type in rest argument can't accpect less argument. #48663
Comments
Duplicate of #45972. Used search terms: `source has but target allows only" |
I'm... not sure this is a duplicate of that, since there are no leading rest elements here to make the analysis weirder. Maybe the same underlying issue is happening in both places? Anyway this one feels more like a bug to me, since the following is fine: const f1: (x: string | number) => void = x => { };
const f2: (x: string | number, y: string | number) => void = f1; // okay
const f3: (...args: [number, string] | [string, number]) => void = f2; // okay And while transitivity of assignability isn't the be-all and end-all for TypeScript, it's nice to be able to reason about things this way when possible. |
Sorry to copy my #49218 (comment) here:
|
Not exactly the same issue, but probably the same root cause: const func: (arg1: string, arg2?: string) => void = (...args: [string] | [string, string]) => undefined; // Error Also: type Func = (...args: [string] | [string, string]) => void;
type Test = Func extends (arg1: string, ...args: any[]) => any ? true : false; // false
// Workaround:
type Test = Func extends (...args: infer Args) => any ? (Args extends [string, ...any[]] ? true : false) : false; // true |
Bug Report
π Search Terms
source has but target allows only
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
throw error
π Expected behavior
no error
The text was updated successfully, but these errors were encountered: