unacy / Relax
Type Alias: Relax<T>
ts
type Relax<T> = T | Unwrap<T>;Defined in: packages/core/src/types.ts:324
Relax a branded unit type to accept either the branded form or its raw unwrapped value. Useful for APIs that should accept both WithUnits<T, M> and plain T interchangeably.
Type Parameters
| Type Parameter |
|---|
T |
Remarks
Use Relax<T> in converter or utility signatures where callers may hold a plain value (e.g., coming from a JSON payload) alongside properly branded values. The type still communicates intent while remaining ergonomic.
Example
typescript
function display(temp: Relax<Celsius>): string {
return `${temp}°C`; // accepts both: Celsius brand or plain number
}
display(25); // OK — plain number
display(25 as Celsius); // OK — brandedUse When
Writing utility functions that wrap or log branded values and should remain usable before the caller has set up a full registry.
Avoid When
Writing converter functions that must enforce the source brand — use the explicit branded type (Celsius) to preserve the safety guarantee.