microsoft / microsoft/TypeScript
A tuple containing a spread not at the trailing edge has its minimum length calculated incorrectly
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
- tuple
- spread
🕗 Version & Regression Information
It happens in v4.9.5, no idea about other versions.
⏯ Playground Link
💻 Code
type FN1 <T> = (...args: string[]) => T;
type FN2 <T> = ( ...args: [consumed: string, ...groups: string[], input: string, index: string] ) => T;
const fn1: FN1<number> = ( a, b ) => 0;
const fn2: FN2<number> = ( a, b ) => 0;
🙁 Actual behavior
TS complains about my fn2, with the following error:
Type '(a: string, b: string) => number' is not assignable to type 'FN2<number>'.
Types of parameters 'b' and 'groups' are incompatible.
Type '[...groups: string[], input: string, index: string]' is not assignable to type '[b: string]'.
Source has 2 element(s) but target allows only 1.(2322)
If I'm interpreting it correctly it is saying like "hey you defined two arguments, but maybe this tuple only has one item in it.
🙂 Expected behavior
If I'm interpreting the error correctly then the error is wrong because there's no scenario where that tuple has just one item in it, minimum it will always have 3.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report in the linked TypeScript Playground using the tuple and function types from the issue. Trace the compiler's tuple minimum-length calculation for spreads in non-trailing positions. Done means the example no longer reports that the source tuple may have only one element, while the existing diagnostic behavior remains correct for genuinely short tuples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100