Closed
Description
Due to Amount
being a generic, with a type parameter T extends Quantity.Quantity
, all Amount
s are interchangeable.
This happens since T extends Quantity.Quantity
won't give you one of the types in the union Quantity.Quantity
, but all types that extends any of them.
https://github.com/dividab/uom/blob/master/src/amount.ts#L11
In essence, this is totally OK:
const foo: Amount.Amount<Quantity.Temperature> = Amount.create(0, Units.Hour);
It is also very deceptive, because if you remove the explicity typing of foo
, its type is correct ( Amount.Amount<"Duration">
), but that will still not prevent assigning it to the wrong type.
const foo = Amount.create(0, Units.Hour);
const bar: Amount.Amount<Quantity.Temperature> = foo;
References:
Metadata
Metadata
Assignees
Labels
No labels