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

Remove Quantity #4

Open
jonaskello opened this issue Nov 14, 2019 · 2 comments
Open

Remove Quantity #4

jonaskello opened this issue Nov 14, 2019 · 2 comments

Comments

@jonaskello
Copy link
Member

jonaskello commented Nov 14, 2019

I'm not sure why we need to export Quantity? It is only types that are exported. If you want to construct an amount I guess the Quantity type parameters is always infered from the unit:

const amount = Amount.create(10, Units.Meter);

What would be an example usage of Quantity as it is exported now?

@jonaskello
Copy link
Member Author

It is needed to type input params:

function add(length1: Amount<Quantity.Length>, length2: Amount<Quantity.Length>) {
  ....
}

@jonaskello
Copy link
Member Author

However when you are typing something like an amount, you can use Units to get the quantity type. This is becuase Units exports type for all quantities, and const for all units. So if you use Units.Foo where typescript expects a type, you will get the quantity type Foo. If you use Units.Foo where typescript expect an actual value, you will get the unit Foo.

So the above example can be written without Quantity like this:

function add(length1: Amount<Units.Length>, length2: Amount<Units.Length>) {
  ...
}

@jonaskello jonaskello reopened this Nov 18, 2019
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

1 participant