#Detecting aliases to "resolved" types

11 messages · Page 1 of 1 (latest)

deep mulch
#
type TypeWrapper<T> = T;
type Check = TypeWrapper<number> extends number ? true : false; // will be true

Is it possible to develop logic to have the Check type be false?

#

The desire is to detect which of my own types are being used vs "standard" types

winged quail
#

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?

deep mulch
#

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

winged quail
#

what does the decorator in question do?

deep mulch
#

Runs some arbitrary code

zinc vault
#

@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};
deep mulch
#

How would this work?

type MySpecialNumber = Branded<number, "Special">; //Not a built-in there are various implementations

Not sure I understand the example