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've seen this comment and I came across the following idea.
interfaceOverloads{0: (t1: number)=>number;1: (t1: number,t2: number)=>number;}interfaceGenerate<Prependextends[]|[string]>{(...args: [...Prepend, ...Parameters<Overloads[0]>]): ReturnType<Overloads[0]>;(...args: [...Prepend, ...Parameters<Overloads[1]>]): ReturnType<Overloads[1]>;}typeNormal=Generate<[]>;// Generate OverloadstypePrepended=Generate<[string]>;// Generate Overloads with leading argument of type stringconstnormal: Normal=(t1: number,t2?: number)=>{returnt1+(t2===undefined ? 0 : t2);}constprepended: Prepended=(s: string,t1: number,t2?: number)=>{console.log(s);returnt1+(t2===undefined ? 0 : t2);}console.log(normal(1));console.log(normal(1,2));console.log(prepended("one",1));console.log(prepended("two plus three",2,3));
Technically this approach could do the job, but there are three problems - argument names get lost, doc-strings get lost and the final interfaces/types become completely unreadable :).
The text was updated successfully, but these errors were encountered:
I've seen this comment and I came across the following idea.
Technically this approach could do the job, but there are three problems - argument names get lost, doc-strings get lost and the final interfaces/types become completely unreadable :).
The text was updated successfully, but these errors were encountered: