A function fn has the overloaded signatures:
public fn(...arg:T[]);
public fn(args:T[]);
so that fn can be called using either fn([T1,T2,T3]) or fn(T1,T2,T3)
What is the "best" definition for that function ? (one that encourages my IDE to enforce the typing and that avoids arguments type testing boilerplate as much as possible)
Obviously, I can implement a fn(args) definition and test typeof arguments[0] in the implementation, but it would seem that since both have a parameter of type T[], something less generic can be done.
(typescript 1.0.1)
EDIT
What I would like to avoid is something like this:
public fn(...arg:string[]);
public fn(args:string[]);
public fn() {
if (typeof arguments[0] === 'string') {
//fn(...args:string[]) called
}
else {
}
}
This seriously weakens the purpose of declaring
public fn(...arg:string[]);
public fn(args:string[]);
in the first place and this does not benefit from the fact that the parameter type isstring[] in both cases
(declaring the definition with the implementation fn() as private would have been an improvement but all definitions must have the same visibility)
avoids arguments type testing boilerplate as much as possiblee.g.?