TypeScriptadvanced
Conditional types + infer to extract a function's return type
type AsyncReturnType<Fn extends (...args: never[]) => unknown> = Fn extends (
...args: never[]
) => Promise<infer R>
? R
: Fn extends (...args: never[]) => infer RBuild a return-type extractor that also unwraps the Promise, so async and sync functions land on the same resolved type.