I have a function that wraps another function that returns type any that I cannot change (it's a library).
I would like to be able to return a type in my wrapper function based on properties given as input in a config object.
e.g.
export interface Config<T> {
options: T[];
multiple: boolean;
extra?: SomeExtraConfig;
}
List of interfaces it should return based on the above interface ^
// if `multiple: true`
{
selection: T[];
}
// if `multiple: false`
{
selection: T;
}
// if `extra` defined`
{
selection: T | T[]; // selection type based on `multiple`
extraData: SomeInterface;
}
Maybe I can just do conditional if statements to assert different return types, but wondering if there is any nifty tricks I can employ.