unacy / TypedMetadata
Type Alias: TypedMetadata<T>
ts
type TypedMetadata<T> = Simplify<{
name: string;
type: T extends PrimitiveType ? ToPrimitiveTypeName<T> : T;
}>;Defined in: packages/core/src/types.ts:466
Metadata type for units with explicit type information.
For primitive types, type is the type name string (e.g., 'number'). For non-primitive types, type IS the actual value:
- Enum: the enum object itself
- Class: the class constructor
- Record: the schema object
{ x: 'number', y: 'string' } - Tuple: the tuple schema array
['number', 'string']
Type Parameters
| Type Parameter | Description |
|---|---|
T extends SupportedType | The SupportedType that this metadata describes |
Example
typescript
// Primitive
const CelsiusMeta = { name: 'Celsius' as const, type: 'number' as const } satisfies TypedMetadata<number>;
// Enum
enum Direction { North, South, East, West }
const DirectionMeta = { name: 'Direction' as const, type: Direction } satisfies TypedMetadata<typeof Direction>;
// Record schema
const PointMeta = { name: 'Point' as const, type: { x: 'number', y: 'number' } as const } satisfies TypedMetadata<{ x: number; y: number }>;Use When
You want WithTypedUnits<M> to automatically resolve the correct base type from the metadata, avoiding the need to specify it manually.
Pitfalls
NEVER widen the type field to a general string or object — the type inference chain from TypedMetadata → WithTypedUnits → UnitAccessor depends on the literal or structural type being preserved at compile time.
Config
Additional fields beyond name and type (e.g., symbol, description) are permitted and accessible via the registry accessor.
See
WithTypedUnits