Skip to content

unacy / RelaxedConverter

Type Alias: RelaxedConverter<TInput, TOutput> ​

ts
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 ParameterDescription
TInputSource unit-tagged type
TOutputDestination unit-tagged type

Parameters ​

ParameterType
inputTInput

Returns ​

Unwrap<TOutput>

Example ​

typescript
// No cast needed on the return value
const c2f: RelaxedConverter<Celsius, Fahrenheit> = (c) => (c * 9/5) + 32;
                                                           // returns number, not Fahrenheit

Use 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

Released under the MIT License.