Skip to content

Conditional types for UnitTimes and UnitDivide #22

@jonaskello

Description

@jonaskello

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions