You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was not satisfied with the limitation of being able to pass only 2 operands, so I created a recursive type MultipleIntersection:
typeMultipleIntersection<Aextendsany[]>=Aextends[infer F, ...infer Rextendsany[]]
? Intersection<F,Rextends[infer L] ? L : MultipleIntersection<R>>
: never;typex={a: string;}typey={b: number;}typez={c: boolean;}typew={d: string[];}typetestCortege=[x,y,z,w];typetest=MultipleIntersection<testCortege>// x & y & z & w// Basically my MultipleIntersection type does the following:typevalidTest=Intersection<testCortege[0],Intersection<testCortege[1],Intersection<testCortege[2],testCortege[3]>>>
Generally speaking, in the implementation of the MultipleIntersection type, if I replace the Intersection type helper with any other binary type helper, I would get the "Multiple" (or n-ary, aka variadic) version of that type.
My question is: is it possible (is there any TS syntax for that) to create a generic VariadicOperation<A extends any[], O extends ???what> type that would allow to pass a binary type-helper?
π Search Terms
type helpers as type parameters, recursive types, variadic type
β Viability Checklist
β Suggestion
Consider the following code sample:
I was not satisfied with the limitation of being able to pass only 2 operands, so I created a recursive type
MultipleIntersection
:Generally speaking, in the implementation of the
MultipleIntersection
type, if I replace theIntersection
type helper with any other binary type helper, I would get the "Multiple" (or n-ary, aka variadic) version of that type.My question is: is it possible (is there any TS syntax for that) to create a generic
VariadicOperation<A extends any[], O extends ???what>
type that would allow to pass a binary type-helper?full code example
π Motivating Example
Typescript is finally Turing complete with this feature!!!
π» Use Cases
The text was updated successfully, but these errors were encountered: