API reference@evolu/commonType › ValidateOutput

type ValidateOutput<T> =
  IsUnion<T> extends false
    ? T
    : CompileTimeError<
        "Type",
        "Output Type must be one concrete Type node. Pass a Union Type node instead of a union of Type nodes."
      >;

Defined in: packages/common/src/Type.ts:2018

Requires one concrete output Type node in a factory parameter.

Rejects TypeScript unions of Type nodes. A union Type is one concrete node and remains valid. Use an intersection with the inferred parameter type to preserve its specific Type. This guard performs no runtime validation.

Example

import {
  assertSame,
  Number,
  String,
  union,
  type AnyType,
  type ValidateOutput,
} from "@evolu/common";

const defineOutput = <T extends AnyType>(type: T & ValidateOutput<T>): T =>
  type;

assertSame(defineOutput(String), String);

const Value = union(String, Number);
assertSame(defineOutput(Value), Value);

const uncertain = String as typeof String | typeof Number;
// @ts-expect-error Output Type must be one concrete Type node. Pass a Union Type node instead of a union of Type nodes.
defineOutput(uncertain);