microsoft / microsoft/TypeScript
Rest element type not recognized for inner array types
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
Hello,
The compiler doesn't recognize an inner array type as an "array type" when inferred in a conditional type.
🔎 Search Terms
I searched for array, rest element, inner array type, multidimensional array type.
Couldn't find anything.
⏯ Playground Link
Playground link with relevant code
💻 Code
The compiler complains with the following code:
type PushToTopArray<T, ArrayOfArray extends any[][]> =
ArrayOfArray extends [infer TopArray, ...infer Rest] ?
[[T, ...TopArray], ...Rest] :
never;
🙁 Actual behavior
with error: A rest element type must be an array type. (2574) on ...TopArray.
🙂 Expected behavior
But since ArrayOfArray extends any[][], the inferred TopArray should be of type any[] and therefore satisfy the rest element type.
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
Start with the linked TypeScript Playground reproduction and confirm the error on the inferred TopArray rest element in the conditional type. Trace the compiler's conditional-type inference and rest-element validation, then add coverage showing that the inferred inner array is accepted and the reproduction type-checks without error.
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
- 35/100