#Detecting aliases to "resolved" types
11 messages · Page 1 of 1 (latest)
no. typescript has a structural type system, meaning two types which share the same structure are equivalent
detect which of my own types are being used vs "standard" types
why do you want to do this?
I have decorated properties in a class of which I want to detect with TypeScript. AFAIK there's no way to detect a decorated property. So my idea was to set the type of the decorated property to a TypeWrapper type to be able to detect whether it is decorated or not at compile time
what does the decorator in question do?
Runs some arbitrary code
@deep mulch There are some workarounds people do for nominal types, like
type MySpecialNumber = Branded<number, "Special">; //Not a built-in there are various implementations
... but the point of those is that number is not assignable to MySpecialNumber, but the reverse would be true.
Trying to make a "special number" type that isn't assignable to number I think makes less sense.
But I mean, in a sense this works:
type TypeWrapper<T> = { __wrapped: T};
How would this work?
type MySpecialNumber = Branded<number, "Special">; //Not a built-in there are various implementations
Not sure I understand the example