I have a function with an object as argument:
// Types
type Params = {
first: string;
second: number;
third?: boolean;
};
type FunctionA = (params: Params) => { [key: string]: any } | void;
// Function
const functionA: FunctionA = params => {
// ... do something
if (params.third) {
return {one: "object"}
}
};
So basically, what I want to achieve is that if third has been submitted, I want that the function return type is {[key: string]: any}. If third is not submitted, I want it to be never.
I have found solutions where the return type of a function changes according to the argument which has been returned but nothing, if the object is an argument and with a return type which is different from the argument type.
Is this even possible?
Thanks! Any help appreciated!