Provide a core types Type (result of typeof)
β Compilation target
es2015
β Library
none
Missing / Incorrect Definition
I could not find a type that provides the result of typeof. The workaround is
declare let a: unknown;
const b = typeof a;
type Types = typeof b;
Sample Code
export function polymorph(type: Types){
switch(type){
///case ...
}
}
Documentation Link
No response
This would fall under: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
It might be worth pointing out that any userland definition won't be forwards compatible if a new primitive ever gets added to the language. πΆβπ«οΈ
It might be worth pointing out that any userland definition won't be forwards compatible if a new primitive ever gets added to the language. πΆβπ«οΈ
How so? Isn't the workaround in the OP forward compatible? It's also highly unlikely new primitives will be added to the language any time soon anyway (note that the records and tuples proposal isn't suggesting to add new primitive types anymore).
How so? Isn't the workaround in the OP forward compatible?
That workaround requires runtime code (typeof a). This means that a pure type-level implementation (type TypeOfResult<T> = ...) is impossible if you want it to be forwards compatible. This also means that such an implementation can't be served as a library, which refutes some of the No New Utility Types rationales.
It's also highly unlikely new primitives will be added to the language any time soon anyway
Yup π similarly Decimals aren't going to be a new primitive, although some people are arguing that non-primitive Decimals aren't as useful as primitive one.
This issue has been marked as "Declined" and has seen no recent activity. It has been automatically closed for house-keeping purposes.