unacy / RelaxedConverter
Type Alias: RelaxedConverter<TInput, TOutput>
type RelaxedConverter<TInput, TOutput> = (input) => Unwrap<TOutput>;Defined in: packages/core/src/converters.ts:169
A converter that accepts the branded input type but returns unwrapped (plain) output. This eliminates the need to cast return values to branded types inside converter functions, while preserving full autocompletion on the input parameter.
Since Tagged<T, ...> extends T, strict converters returning branded types are also assignable to this type.
Type Parameters
| Type Parameter | Description |
|---|---|
TInput | Source unit-tagged type |
TOutput | Destination unit-tagged type |
Parameters
| Parameter | Type |
|---|---|
input | TInput |
Returns
Unwrap<TOutput>
Example
// No cast needed on the return value
const c2f: RelaxedConverter<Celsius, Fahrenheit> = (c) => (c * 9/5) + 32;
// returns number, not FahrenheitUse When
Writing converter implementations where casting the return value to a branded type is inconvenient. The registry handles branding internally.
Avoid When
The converter is used outside the registry — callers of a standalone RelaxedConverter receive an unwrapped value with no unit brand.
Pitfalls
NEVER pass a RelaxedConverter result directly to another function that expects a branded type without going through the registry — the unbranded return value defeats the type safety guarantee at the call site.
See
- Converter
- RelaxedBidirectionalConverter