You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The principle is that the truly private property #brand must exist for it to be assignable. This property does not really exist at runtime but its existence is expected at compile time and so has these useful properties.
This can't be replicated outside of going through the Brand type because the Branded class does not exist anywhere else and a truly private property from one class is not assignable to another. A similar effect could be achieved through a unique symbol but this would show up in keyof Brand<...> hence why a truly private property is used. Plus it would make it more difficult to make BrandName explicitly invariant outside of a class.
The text was updated successfully, but these errors were encountered:
I've added a new
Brand
type tohelperTypes
. One of the things it's most useful for are enums.The pattern to implement is as follows:
This helps people use enums appropriately and avoid mistakes.
Brand is implemented as follows:
The principle is that the truly private property
#brand
must exist for it to be assignable. This property does not really exist at runtime but its existence is expected at compile time and so has these useful properties.This can't be replicated outside of going through the
Brand
type because theBranded
class does not exist anywhere else and a truly private property from one class is not assignable to another. A similar effect could be achieved through aunique symbol
but this would show up inkeyof Brand<...>
hence why a truly private property is used. Plus it would make it more difficult to makeBrandName
explicitly invariant outside of a class.The text was updated successfully, but these errors were encountered: