microsoft / microsoft/TypeScript
Tail-Recursion Elimination on Conditional Types
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
recursion,instantiation,Tail-Recursion
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
type A = { a: string, b: number }
type B = { a: number, b: string }
type UnionTheTypeOfTheSameKey<R, H> = Omit<R, keyof H> & { [k in keyof H]: k extends keyof R ? R[k] | H[k] : H[k] }
type compute<T> = { [k in keyof T]: T[k] }
type foo<T extends object[], result = {}> = T extends [infer head extends object, ...infer rest extends object[]]
? foo<rest, UnionTheTypeOfTheSameKey<result, head>> : result
// expect ok type test = {a:string|number,b:string|number}
type test = compute<foo<[A, B,]>>
// When the foo length is greater than 33 The result is wrong. type test1 = {a:any,b:any}
type test1 = compute<foo<[A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B]>>
🙁 Actual behavior
// When the foo length is greater than 33 The expected is wrong. type test1 = {a:any,b:any}
type test1 = compute<foo<[A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B]>>
🙂 Expected behavior
// When the foo length is Less than 999 expected test1 = {a:string|number,b:string|number}
type test1 = compute<foo<[A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B, A, B]>>
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 by reproducing the recursive conditional-type example in the linked TypeScript Playground using the stated version, then compare the result with the expected type and newer versions. Done means the example produces {a: string|number, b: string|number} for inputs shorter than 999 elements instead of widening to any.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100