This is a simplified version of the scenario I'm contending with written in psuedo code.
function MyHOF<Payload extends object | undefined>(config: {
payload?: Payload
}) {
// return this if payload isn't configured
return (config?: {options: any}) => any
// return this if payload signature is provided
return (config: {options: any, payload: Payload}) => any
}
I've made several attempts to write this and come up with overly complicated type signatures that don't work. Do I need to do something along the lines of:
type DoAction<Payload> = Payload extends undefined
? { (config?: {options: any}): any }
: { (config: {options: any, payload: Payload}) }