Repository navigation
Union tuple type in rest argument can't accpect less argument.ย #48663
Description
Activity
MartinJohns commented
on Apr 13, 2022 ContributorMore actionsDuplicate 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.
Reacted by Martin Johns and Ovidijus Parsiunas- addedBugA bug in TypeScriptA bug in TypeScriptHelp WantedYou can do thisYou can do this
on Apr 13, 2022 graphemecluster commented
on May 29, 2022 ContributorMore actionsSorry to copy my #49218 (comment) here:
I think the easiest way to solve all the related issues is to wrap all the arguments into a tuple with rest syntax, i.e.
item => {}should become(...[item]) => {}and([first, ...rest], foo, ...args) => {}should work just like(...[[first, ...rest], foo, ...args]) => {}.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
- addedDomain: check: Variance RelationshipsThe issue relates to variance relationships between typesThe issue relates to variance relationships between types
on Oct 16, 2025
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