Function Utility Types
Function Utilities
π¨βπΌ TypeScript provides utilities for working with function types. These are
essential when wrapping or transforming functions.
function scoreGame(points: number, bonus: boolean) {
return points + (bonus ? 10 : 0)
}
type ScoreResult = ReturnType<typeof scoreGame>
type ScoreArgs = Parameters<typeof scoreGame>
ReturnType<T>- Get the return type of a functionParameters<T>- Get parameter types as a tupleAwaited<T>- Unwrap Promise types
π¨ Open
and:
- Use
ReturnTypeto extract a function's return type - Use
Parametersto get a function's parameter types - Use
Awaitedto unwrap Promise types - Create a wrapper function that preserves types


