Is it possible to get the return type of a function that returns another function?
const creator = (deps: CreatorDependencies) => () => {
return {
foo: 1,
bar: 2,
};
}
I expect to get this
{ foo: number; bar: number; }
This is a use case for TypeScript's ReturnType<Type> utility type.
type CreatorReturn = ReturnType<ReturnType<typeof creator>>
ReturnType<typeof creator> gives you the type of the function returning your object, and wrapping it in another ReturnType<> gives you the object type needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With