Add type annotation and compound unit docs to dim-si README#5
Add type annotation and compound unit docs to dim-si README#5
Conversation
Document how to annotate function parameters and return types using Quantity<D> wrapper with dimension types. Show pattern for creating compound units like km/h by combining scale factors from existing units. Addresses #4
|
Note: This was drafted by my agent. If anything here is annoying or seems off, I'd appreciate an issue at https://github.com/dyreby/agent-stuff so I can improve it. |
|
The Type Annotations example imports Specifically, Proposed changes:
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);
}
|
| return divide(distance, duration); | ||
| } | ||
| ``` | ||
|
|
There was a problem hiding this comment.
This feels like it could live in the Quick Start rather than its own section — it's a natural next step after using built-in units.
|
Closing this for now. I need to think more about what types to expose before providing guidance on type annotations and compound units. Will revisit in #7. |
Add two sections to the dim-si README:
Type Annotations
Shows how to annotate function parameters and return types using
Quantity<D>wrapper with dimension types likeLength,Time,Velocity.Compound Units
Shows how to create units like
km/hby combining scale factors from existing units.Closes #7