Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All amounts are effectively the same type. #4

Closed
geon opened this issue Oct 5, 2018 · 1 comment
Closed

All amounts are effectively the same type. #4

geon opened this issue Oct 5, 2018 · 1 comment

Comments

@geon
Copy link
Member

geon commented Oct 5, 2018

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:

@Jontem
Copy link
Contributor

Jontem commented Oct 31, 2018

I believe this is fixed now.

@Jontem Jontem closed this as completed Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants