'TypeScript return type of typeof should be string?
type typeof_returntype = ReturnType<typeof typeof> // should be string?
I was just playing around when I noticed that I can't get the return type of the function typeof. Is this by design?
Solution 1:[1]
typeof is an operator not a function, therefore one cannot extract its return type. But one can get "the union of string literal results of typeof as a type if you wrap the operator in a function".
const typeOf = (x: any) => typeof(x);
type typeof_returntype = ReturnType<typeof typeOf>;
// "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jaacko Torus |
