4 ms·
According to Deno it does work. type USD = number & { currency?: "USD" } type CAD = number & { currency?: "CAD" } const fiveUsd : USD = 5; const fiveCa
by TOGoS 2y ago
According 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.