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

Conditional types for UnitTimes and UnitDivide #22

Open
jonaskello opened this issue Nov 19, 2018 · 0 comments
Open

Conditional types for UnitTimes and UnitDivide #22

jonaskello opened this issue Nov 19, 2018 · 0 comments

Comments

@jonaskello
Copy link
Member

jonaskello commented Nov 19, 2018

While it is possible to generically divide any unit by any other unit and get a new unit that works for conversion, it is not possible to get the type of the new unit because we don't know which quantity it should get. To solve that UnitTimes and UnitDivide exists and they support dividing certain units by other units, and returning a correctly typed unit in the resulting quantity.

However it is still not possible to have a generic Amount.divide or Amount.times.

This might be solvable by using conditional types in typescript. Something like:

type Divide<Q1, Q2> = Q1 extends Length ? 
  Q2 extends Duration ? Velocity : 
  Q2 extends Length ? Dimensionless : never : never.
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