API reference@evolu/commonType › ExtractTyped

type ExtractTyped<Output, Name> = Extract<
  Output,
  {
    type: Name;
  }
>;

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

Extracts members of a Typed Output union by their type literal.

The requested tag is constrained to the union's actual discriminator values, so a misspelling is a TypeScript error instead of silently producing never.

Example

import {
  assertType,
  String,
  discriminatedUnion,
  typed,
  type ExtractTyped,
} from "@evolu/common";

const Create = typed("Create", { id: String });
const Delete = typed("Delete", { id: String });
const Message = discriminatedUnion(Create, Delete);
type Message = typeof Message.Output;

type CreateMessage = ExtractTyped<Message, "Create">;

assertType<typeof Create.Output, CreateMessage>();

// @ts-expect-error "Cretae" is not a Message type.
type _Typo = ExtractTyped<Message, "Cretae">;