type-alias / @typed/guard

AnyOutput

Builds the tagged output union produced by any.

Package version
1.0.0-beta.7
Category
Type utilities
Since
1.0.0

Import

import type { AnyOutput } from "@typed/guard";

Signatures

export type AnyOutput<GS extends Readonly<Record<string, GuardInput<any, any, any, any>>>> = [
    {
        [K in keyof GS]: {
            readonly _tag: K;
            readonly value: Guard.Output<GS[K]>;
        };
    }[keyof GS]
] extends [
    infer R
] ? R : never;

Why

Preserving each record key in _tag lets downstream code narrow the winning Guard’s value exhaustively.

Ownership and lifetime

This compile-time type acquires no resources and has no runtime lifetime.

Examples

import type { AnyOutput, Guard } from "@typed/guard"
type Output = AnyOutput<{ text: Guard<unknown, string>; count: Guard<unknown, number> }>

Source