3 ms·
Making it optional doesn't work, the brand property needs to be required. Doesn't mean that you actually have to define the property at runtime, you'd usually c
by williamdclt 2y ago
Making it optional doesn't work, the brand property needs to be required.
Doesn't mean that you actually have to define the property at runtime, you'd usually cast the number to USDollars where relevant
- TOGoS 2y agoAccording to Deno it does work. type USD = number & { currency?: "USD" } type CAD = number & { currency?: "CAD" } const fiveUsd : USD = 5; const fiveCad : CAD = fiveUsd; console.log("How many CAD? " + fiveCad); Results in an error, Type '"USD"' is not assignable to type '"CAD"'. If by "doesn't work" you mean that the implicit number->USD conversion is allowed, then I disagree with the judgement, as that is by design. But once the values are in variables of more specific types, the type-checker will catch it.