Microsoft/TypeScript
GitHub ã§èŠãTail-Recursion Elimination on Conditional Types
Open
#54,082 opened on 2023幎5æ1æ¥
Experience EnhancementHelp WantedSuggestion
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
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]>>