I have defined the following two function signatures in the same Typescript class, i.e.,
public emit<T1>(event: string, arg1: T1): void {}
and
public emit<T1,T2>(event: string, arg1: T1, arg2: T2): void {}
However when transpiling the typescript I get the following error
error TS2393: Duplicate function implementation.
I thought you could overload functions in typescript providing the number of parameters in the function signature were different. Given that the above signatures have 2 and 3 parameters respectively, why am I getting this transpilation error?
arg2??arg2?I'll still have to provide the generic typeT2inemit<T1,T2>even though I may not actually be usingT2. I guess I'm trying to achieve something similar to c#'sFuncandActiondelegate signatures. But there could be a better way.T2in the definition of the function, this harms nothing. If are referring to calling the function, providing any type, as inemit<number, string>shouldn't be necessary since types will be picked up from the types of the arguments. Anyway, if necessary, write out the two declarations with no body (just a semi-colon), then write one implementation that somehow checks for the presence ofarg2, or perhaps assigns it a default value.