TypeScript adds a typeof
operator you can use in a type context to refer to the type of a variable or property:
If we try to use ReturnType
on a function name, we see an instructive error:
TypeScript intentionally limits the sorts of expressions you can use typeof
on.