Reputation: 133
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; }
Upvotes: 3
Views: 610
Reputation: 1843
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.
Upvotes: 5