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
Type Z here resolves to string[], not string | string[], because overloads just get the last declared one matched.
I am curious to know if this is possible to implement. As far as I can tell this also affects the standard function overload approach, e.g.:
functionfun(thing: string): void;functionfun(stuff: string[]): void;// function fun(thing: string | string[]); // uncomment me to allow type Y to match `string`.functionfun(thing: string|string[]){console.log(Array.isArray(thing) ? thing.join('; ') : thing);}typeF={(thing: string): void;(things: string[]): void;}typeZ=Parameters<F>[0]typeY=Parameters<typeoffun>[0];letzz:Z='abc';letyy:Y='abc';
To be clear, what I'm asking for is a util e.g. OverloadParameters which in this case would produce for type OverloadParameters<F> a value of [string] | [string[]]. I'm actually currently unsure of how to unwrap the parameter-array situation there but I'm sure it's manageable. As expected, the type ([string] | [string[]])[0] is string | string[].
The text was updated successfully, but these errors were encountered:
A general solution working for N overloads seems elusive. In practical terms we only ever need this for up to say 5 overloads. So unrolling it seems practical. A recursive implementation would be nice, but may lead to longer compilation time.
Example situation:
Type Z here resolves to
string[]
, notstring | string[]
, because overloads just get the last declared one matched.I am curious to know if this is possible to implement. As far as I can tell this also affects the standard function overload approach, e.g.:
To be clear, what I'm asking for is a util e.g.
OverloadParameters
which in this case would produce for typeOverloadParameters<F>
a value of[string] | [string[]]
.I'm actually currently unsure of how to unwrap the parameter-array situation there but I'm sure it's manageable.As expected, the type([string] | [string[]])[0]
isstring | string[]
.The text was updated successfully, but these errors were encountered: