Discriminant fields tie runtime branches to a finite set of names. Extracting their union keeps routing or rendering logic aligned with actual variants.
Worked example
type Result =
{ kind: "ok"; value: number } | { kind: "error"; message: string };
const results: Result[] = [
{ kind: "ok", value: 3 },
{ kind: "error", message: "offline" },
];
console.log(((kind: Result["kind"]) => kind)("ok"));Result
okImplementation notes
A duplicate discriminant across variants can hide an ambiguous state model. A union of names alone will not reveal that duplication.
Try it yourself
Introduce another variant and inspect the resulting set of names.
Open the TypeScript example →Editorial date September 20, 2025 · Published December 6, 2026