Sometimes, we want to obtain the return type of a function with TypeScript.
In this article, we’ll look at how to obtain the return type of a function with TypeScript.
How to obtain the return type of a function with TypeScript?
To obtain the return type of a function with TypeScript, we can use the ReturnType
type.
For instance, we write
type T10 = ReturnType<() => string>;
to get the type of of the () => string
function type and assign it to T10
.
Therefore T10
is string
.
Conclusion
To obtain the return type of a function with TypeScript, we can use the ReturnType
type.