Skip to content

Make dim-si types easy to use for end users #7

@dyreby

Description

@dyreby

Users of dim-si shouldn't need to reach into lower-level packages (dim-quantity, dim-unit) to annotate their functions. The key types for function signatures are Linear and Affine (from dim-unit), which express whether a parameter is a regular quantity or an affine one (like absolute temperature).

Approach:

  • Re-export Linear and Affine from @isentropic/dim-si root module
  • Document Linear for standard quantity annotations (e.g., Linear<Length>, Linear<Velocity>)
  • Document Affine for affine quantities (e.g., Affine<Temperature>)
  • Update README prose to explain Linear vs Affine instead of referencing Quantity

Example of what end-user code should look like:

import type { Linear } from "@isentropic/dim-si";
import type { Length } from "@isentropic/dim-si/length";
import type { Time } from "@isentropic/dim-si/time";
import type { Velocity } from "@isentropic/dim-si/velocity";
import { divide } from "@isentropic/dim-si/ops";

function speed(
  distance: Linear<Length>,
  duration: Linear<Time>,
): Linear<Velocity> {
  return divide(distance, duration);
}
import type { Affine } from "@isentropic/dim-si";
import type { Temperature } from "@isentropic/dim-si/temperature";
import { kelvin } from "@isentropic/dim-si/temperature";
import { q } from "@isentropic/dim-si/ops";

function toKelvin(temp: Affine<Temperature>): number {
  return q(temp).in(kelvin);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationpkg:dim-sidim-si package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions