discriminated-unions

Stark · 77
Im Registry indexiert

Apply, review, and explain discriminated unions in TypeScript. Use automatically for tasks involving mutually exclusive variants, invalid state prevention, exhaustiveness checking, variant-specific object properties, application state, function arguments, or React props.

Verified installs0
Stars780
Version1.0.0
Qualität76/100 · Stark
Vertrauen77/100 · Vor Installation prüfen
Audit85/100 · Sicher zu testen

Asset-Profil

Recherche und Wissensarbeit

Deep research, source comparison, literature review, RAG, knowledge search, and reports.

Bereich ansehen

Szenario

Recherche-Agents

I need my agent to research a topic, compare sources, and produce a concise report.

Agent-Fit

Claude Code + CLI + Codex

Geeignet für Codex, Claude Code, Cursor, CLI oder benutzerdefinierte Agents.

Installieren

Bereit

npx skills add mkosir/typescript-style-guide --skill discriminated-unions

Wartung

Aktuell

Heute gepusht

Risiko

Sicher zu testen

Quality score needs review

GitHub-Qualität

780

76/100 Qualität · 82/100 Vertrauen

Abdeckungs-Tags

RechercheRecherche-Agentsagent-skill

Review-Notizen

Quality score needs review

Agent-Adoptionskarte

Vertrauen, Audit und Installationsbereitschaft auf einen Blick

Diese Werte kombinieren öffentliche Repository-Metadaten, OpenAgentSkill-Reviewsignale, Wartungsaktualität und Installationsbereitschaft. Sie helfen bei der Vorauswahl, ersetzen aber keine menschliche Prüfung.

Qualität

Stark
76

Solid option that is likely worth shortlisting for production workflows.

Vertrauen

Vor Installation prüfen
77

Gutes Shortlist-Signal, aber der Agent sollte Auditnotizen, Installationsrichtlinien und Ergebnisbelege vor der Ausführung prüfen.

Audit

Sicher zu testen
85

Maschinenlesbare Prüfung von Installationsbereitschaft, Sicherheitsmetadaten, Wartung und Akzeptanzrisiko.

OpenAgentSkill Trust Score v5

Menschliche Prüfung vor Installation

Nach menschlicher oder Sandbox-Prüfung als primären Kandidaten verwenden.

CodexClaude CodeCursorOpenAgentSkill CLI

Stars

780 GitHub-Stars

Repository-Aktivität

780 Stars und 37 Forks

Wartung

Heute gepusht

Lizenz

MIT

Installieren

npx skills add mkosir/typescript-style-guide --skill discriminated-unions

Installationssicherheit

Standard-Paket- oder Laufzeit-Installationspfad

Berechtigungsfläche

filesystem or document access, network or browser access

Agent-Ergebnisse

Noch keine Agent-Ergebnisdaten

Dokumentation

Starker README/SKILL.md-Kontext

Risikoübersicht

Niedriges Metadatenrisiko

  • Quality score needs review

Installationsbereitschaft

Installationspfad verfügbar

  • Installationspfad ist verfügbar
  • Repository-Belege sind verfügbar
  • Lizenz ist angegeben
  • Noch keine Agent-Proven-Ergebnisbelege

Agent-lesbare Metadaten

Maschinenlesbare Entscheidungsdaten für diesen Skill.

Nutze diesen Block oder das eingebettete JSON, um zu entscheiden, ob ein Agent diesen Skill installieren, eine Alternative wählen oder zuerst menschliche Prüfung anfordern soll.

JSON öffnen

Geeignete Aufgaben

  • Coding-Agents-Workflows
  • Claude-Code-Teams
  • Teams, die GitHub-Adoptionssignale schätzen
  • Inspect source files

Geeignete Agents

CodexClaude CodeCursorOpenAgentSkill CLICLI

Installationsentscheidung

Befehl
npx skills add mkosir/typescript-style-guide --skill discriminated-unions
Richtlinie
Prüfen
Menschliche Prüfung
Ja

Vertrauen und Risiko

Vertrauen
77/100
Audit
85/100
Risikoebene
Sicher zu testen

Ergebnis-Loop

Endpoint
/api/agent/outcome
Event-ID
resolve
Ergebnisse
5

Installationsbefehl

npx skills add mkosir/typescript-style-guide --skill discriminated-unions

Nicht verwenden, wenn

  • Teams, die ein vom Anbieter unterstütztes SLA benötigen
  • Hochregulierte Umgebungen ohne interne Sicherheitsprüfung
  • No major risk signals from current metadata
  • Quality score needs review
  • Production credentials, payments, or irreversible account changes without explicit human review

Agent-Sicherheit v2

69/100 · Vor Installation prüfen

GeprüftPrüfen

Gute Audit- und Sicherheitssignale ohne Hochrisiko-Berechtigungshinweise in öffentlichen Metadaten.

Prüfen Sie die Audit-Seite und erlauben Sie die Agent-Installation dann in einem Sandbox-Workflow.

Per API auflösen

Mittel

Netzwerkzugriff

Die Skill ruft wahrscheinlich Remote-Seiten, APIs, Repositories oder externe Dienste ab.

Mittel

Dateisystemzugriff

Die Skill kann Projektdateien, Dokumente, generierte Artefakte oder den lokalen Arbeitsbereich lesen oder schreiben.

  • Quality score needs review

Installationsziele

Diesen Skill im Agent-Workflow installieren

Über den öffentlichen Endpunkt erhältst du Befehl, Sicherheitscheckliste, Ziel-Prompts und kanonische Links.

skill install

OpenAgentSkill CLI

Resolve policy, run the source installer safely, and report a verified install receipt.

$ npx --yes https://github.com/Leon-Drq/openagentskill/releases/download/cli-v0.2.1/openagentskill-0.2.1.tgz install mkosir-discriminated-unions

Agent-Auflösungsplan

Lass einen Agent die Eignung vor der Installation prüfen.

Die Resolve API liefert die beste Skill, Alternativen, Sicherheitsrichtlinien, Auditnotizen, Installationsziel und einen direkt nutzbaren Prompt.

Textplan öffnen

Agent sollte prüfen

  • Task fit and alternatives from Resolve API.
  • Audit score, trust score, and safety policy warnings.
  • Install target compatibility for Codex, Claude Code, Cursor, or CLI.

Prompt kopieren

Task: Use discriminated-unions in this workspace.
Resolve first: https://www.openagentskill.com/api/agent/resolve?task=Use%20discriminated-unions%20for%20an%20agent%20workflow&agent=codex&max_risk=medium
Review install handoff: https://www.openagentskill.com/api/skills/mkosir-discriminated-unions/install
Install command: npx skills add mkosir/typescript-style-guide --skill discriminated-unions
Before running it, summarize audit warnings, required permissions, and the fallback skill if install is risky.

Agent-Übergabe

Gib dem Agent den Installationspfad, nicht noch ein Verzeichnis.

Über den öffentlichen Endpunkt erhältst du Befehl, Sicherheitscheckliste, Ziel-Prompts und kanonische Links.

Installations-API öffnen

Agent-Prompt

Use discriminated-unions for this task. Review https://www.openagentskill.com/api/skills/mkosir-discriminated-unions/install, then install with: npx skills add mkosir/typescript-style-guide --skill discriminated-unions

Registry-Metadaten

Agent-lesbares Profil für die automatische Skill-Auswahl.

Die Registry API stellt Entscheidungs-, Vertrauens-, Audit-, Use-Case- und Installationssignale ohne UI-Scraping bereit.

Manifest öffnen

Agent-Fit

88/100

Coding-Agents

Plattformen

Claude Code

Audit-Bericht

Sicher zu testen · 85/100

Maschinenlesbare Prüfung von Installationsbereitschaft, Sicherheitsmetadaten, Wartung und Akzeptanzrisiko.

Audit-Bericht ansehenEval-Bericht ansehen

Agent-Entscheidungspanel

Primäre Wahl für Coding-Agents

Use this as a leading candidate, then validate the README and install path in your own agent stack.

88
Bereitschaft
Übernehmen
Phase

Rolle im Stack

Primäre Wahl

Primäre Eignung

Coding-Agents

Vertrauenslabel

Produktionsbereit

Installationspfad

Befehl bereit

Verwenden wenn

  • Coding-Agents-Workflows
  • Claude-Code-Teams
  • Teams, die GitHub-Adoptionssignale schätzen

Evidenz

  • 780 GitHub-Stars
  • recent repository activity
  • install command or GitHub repo available
  • Qualitätsprofil 76/100
  • 2 OpenAgentSkill-Interaktionen

zuerst prüfen

  • No major risk signals from current metadata

Implementierungspfad

  1. 1Installieren Sie es in einem Sandbox-Agent und führen Sie eine Coding-Agents-Aufgabe vollständig aus.
  2. 2Compare output quality, latency, and failure behavior against at least one alternative.
  3. 3Promote it into production only after reviewing repository permissions, license, and maintenance signals.

Vertrauensprofil

Vor Installation prüfen

Gutes Shortlist-Signal, aber der Agent sollte Auditnotizen, Installationsrichtlinien und Ergebnisbelege vor der Ausführung prüfen.

77
OpenAgentSkill Trust Score

GitHub-Akzeptanz

Info

780 GitHub-Stars

Star-/Fork-Aktivität

Info

780 Stars und 37 Forks; Issue-Aktivität ist in den aktuellen Metadaten nicht verfügbar

Aktuelle Wartung

Bestanden

Heute gepusht

Lizenzklarheit

Bestanden

MIT

Positive Signale

  • KI-Prüfung genehmigt
  • Installationspfad ist verfügbar
  • Repository-Belege sind verfügbar
  • Kürzlich gewartetes Repository
  • Aussagekräftiges GitHub-Adoptionssignal
  • Der Installationsbefehl weist kein offensichtliches Hochrisikomuster auf
  • Ergebniszyklus ist bereit, benötigt aber den ersten echten Agent-Lauf

Vor Installation prüfen

  • Quality score needs review
  • Noch keine echten Agent-Ergebnisberichte
  • Vor unbeaufsichtigter Installation ist menschliche Prüfung erforderlich

Empfohlene Aktion

Nach menschlicher oder Sandbox-Prüfung als primären Kandidaten verwenden.

Qualitätsprofil

Stark Kandidat für Agent-Workflows

Solid option that is likely worth shortlisting for production workflows.

76
GitHub-Stars
780
Aktualität
Heute
Installationsbereit
Ja
Lizenz
MIT

Workflow-Eignung

Diese Skill in diesen Szenarien nutzen

Workflow-Eignung

Zum vollständigen Workflow hinzufügen

Alternativen-Shortlist

Vor Installation vergleichen

Similar skills that may fit this task.

Alle vergleichen

Übersicht

--- name: discriminated-unions description: Apply, review, and explain discriminated unions in TypeScript. Use automatically for tasks involving mutually exclusive variants, invalid state prevention, exhaustiveness checking, variant-specific object properties, application state, function arguments, or React props. ---

# Discriminated Unions

Apply the TypeScript Style Guide's discriminated-union conventions in the context of the current task.

## Workflow

1. Inspect the consuming repository's conventions and configuration. 2. Let explicit repository conventions take precedence over this opinionated guidance. 3. Apply, review, or explain only the guidance relevant to the task. 4. State important tradeoffs when the appropriate model depends on context or judgment.

## Boundaries

- Use discriminated unions for mutually exclusive variants that require different data. - Do not force a discriminated union when properties may independently be absent or when only a value changes. - Keep TypeScript and ESLint responsible for checks they can enforce automatically. - Do not introduce unrelated TypeScript Style Guide conventions merely because this skill is active.

<!-- BEGIN CANONICAL GUIDE CONTENT -->

## Discriminated Unions {#discriminated-unions}

If there's only one TypeScript feature to choose from, embrace discriminated unions.

A discriminated union is a union of object types that share a property with distinct literal values. Checking that property narrows the value to the matching variant.

Use discriminated unions when variants are mutually exclusive and each variant requires different data. Keep properties optional when they may independently be absent, and use a literal union when only the value changes.

Discriminated unions are a powerful concept to model complex data structures and improve type safety, leading to clearer and less error-prone code. You may encounter discriminated unions under different names, such as tagged unions or sum types, in languages such as C, Haskell, and Rust (in conjunction with pattern-matching).

Advantages of discriminated unions:

- As mentioned in [Required & Optional Object Properties](#required--optional-object-properties), [Function Arguments](#function-arguments), and [Props as Discriminated Type](#props-as-discriminated-type), discriminated unions replace optional properties that depend on a variant with required properties for that variant, reducing complexity. - Exhaustiveness Checking - The configured ESLint rule reports when a switch does not handle every variant of a discriminated union.

<Rule href="https://typescript-eslint.io/rules/switch-exhaustiveness-check/">{`"@typescript-eslint/switch-exhaustiveness-check": "error"`}</Rule>

```ts type Circle = { kind: 'circle'; radius: number }; type Square = { kind: 'square'; size: number }; type Triangle = { kind: 'triangle'; base: number; height: number };

// Create a discriminated union 'Shape', with the 'kind' property to discriminate the type of object. type Shape = Circle | Square | Triangle;

const calculateArea = (shape: Shape) => { // ESLint reports that the switch is missing the 'triangle' case switch (shape.kind) { case 'circle': return Math.PI * shape.radius ** 2; case 'square': return shape.size ** 2; } }; ```

- Avoid code complexity introduced by multiple [boolean flags](#application-state) that represent mutually exclusive states. - Clear code intent, as it becomes easier to read and understand by explicitly indicating the possible cases for a given type. - TypeScript can narrow down union types, ensuring code correctness at compile time. - Discriminated unions make refactoring and maintenance easier by providing a centralized definition of related types. When adding or modifying types within the union, the compiler reports any inconsistencies throughout the codebase. - IDEs can leverage discriminated unions to provide better autocompletion and type inference.

### Practical Applications

#### Required & Optional Object Properties {#required--optional-object-properties}

**Strive to have the majority of object properties required and use optional properties sparingly.**

This approach reflects designing type-safe and maintainable code:

- Clarity and Predictability - Required properties make it explicit which data is always expected. This reduces ambiguity for developers using or consuming the object, as they know exactly what must be present. - Type Safety - When properties are required, TypeScript can enforce their presence and catch missing properties during type checking. - Avoids Overuse of Optional Chaining - If too many properties are optional, it often leads to extensive use of optional chaining (`?.`) to handle potential undefined values. This clutters the code and obscures its intent.

Use optional properties when values may independently be absent. When property presence depends on the object's variant, use a **discriminated union type**.

```ts // ❌ Avoid optional properties when their presence depends on the variant type User = { id?: number; email?: string; dashboardAccess?: boolean; adminPermissions?: ReadonlyArray<string>; subscriptionPlan?: 'free' | 'pro' | 'premium'; rewardsPoints?: number; temporaryToken?: string; };

// ✅ Use a discriminated union so each variant has only its required properties type AdminUser = { role: 'admin'; id: number; email: string; dashboardAccess: boolean; adminPermissions: ReadonlyArray<string>; };

type RegularUser = { role: 'regular'; id: number; email: string; subscriptionPlan: 'free' | 'pro' | 'premium'; rewardsPoints: number; };

type GuestUser = { role: 'guest'; temporaryToken: string; };

// Discriminated union type 'User' ensures clear intent with no optional properties type User = AdminUser | RegularUser | GuestUser;

const regularUser: User = { role: 'regular', id: 212, email: 'lea@user.com', subscriptionPlan: 'pro', rewardsPoints: 1500, dashboardAccess: false, // Error: 'dashboardAccess' property does not exist }; ```

#### Application State

When application states require different data, model the state and its data together with a discriminated union. This prevents invalid combinations, such as loading while holding both data and an error.

```ts // ❌ Boolean flags and optional properties allow invalid state combinations type RequestState = { isLoading: boolean; data?: Products; error?: string; };

// ✅ Each state contains only the data valid for that state type RequestState = | { status: 'idle' } | { status: 'loading' } | { status: 'success'; data: Products } | { status: 'error'; error: string }; ```

#### Function Arguments

When a function accepts mutually exclusive variants that require different properties, use a **discriminated union type**. This decreases complexity in the function's API and ensures that only the required properties are passed for each use case.

```ts // ❌ Avoid optional properties that allow invalid combinations in the function API type NotificationParams = { channel: 'email' | 'sms'; email?: string; phoneNumber?: string; subject?: string; message: string; };

// ✅ Use a discriminated union so each variant requires only its valid properties type EmailNotificationParams = { channel: 'email'; email: string; subject: string; message: string; };

type SmsNotificationParams = { channel: 'sms'; phoneNumber: string; message: string; };

type NotificationParams = EmailNotificationParams | SmsNotificationParams;

export const sendNotification = (params: NotificationParams) => { switch (params.channel) { case 'email': return sendEmail(params.email, params.subject, params.message); case 'sms': return sendSms(params.phoneNumber, params.message); } }; ```

#### React Props

##### Required & Optional Props

**Strive to have the majority of props required and use optional props sparingly.**

Especially when creating a new component for its first or single use case, the majority of props should be required. When the component starts covering more use cases, introduce optional props only for values that may genuinely be absent across those use cases. There are potential exceptions where a component API needs to implement optional props from the start (e.g. shared components covering multiple use cases, UI design system components - button `isDisabled` etc.)

If a component or hook becomes too complex, it should probably be broken into smaller pieces. An exaggerated example: implementing 10 React components with 5 required props each is better than implementing one "can do it all" component that accepts 50 optional props.

##### Props as Discriminated Type

When component variants require different props, use a **discriminated union type**. This approach reduces complexity in the component API and ensures that only the required props are passed for each variant.

```tsx // ❌ Avoid optional props that allow invalid combinations in the component API type AvatarProps = { variant: 'image' | 'initials'; src?: string; alt?: string; initials?: string; };

// ✅ Use a discriminated union so each variant requires only its valid props type ImageAvatarProps = { variant: 'image'; src: string; alt: string; };

type InitialsAvatarProps = { variant: 'initials'; initials: string; };

type AvatarProps = ImageAvatarProps | InitialsAvatarProps;

export const Avatar = (props: AvatarProps) => { switch (props.variant) { case 'image': return <img src={props.src} alt={props.alt} />; case 'initials': return <span>{props.initials}</span>; } }; ```

<!-- END CANONICAL GUIDE CONTENT -->

Technische Details

Version
1.0.0
Lizenz
MIT
Letzte Aktualisierung
23. Aug. 2026
Veröffentlicht
23. Aug. 2026

Entscheidungsübersicht

Primäre Wahl

88
Bereit
Übernehmen
Phase

780 GitHub-Stars

Audit

Installationsprüfung

Installations- und Adoptionsprüfung

85
Sicher zu testen
Sicherheit
86/100
Wartung
100/100
Installieren
92/100
Vollständiges Audit öffnenEval-Bericht ansehen

Von Agent belegte Evidenz

Von Agent belegte Evidenz

Ergebnisberichte nach Resolve, Prüfung, Installation und einem begrenzten Lauf.

0
Belegt
Needs first agent runAuto-Installation: zuerst prüfenLetzter: Unbekannt
Erfolgsrate
Letzter Fehler
Ergebnisse
0
Ausgabequalität
Fehlgeschlagen
0
Nicht relevant
0
Installationen
0
Durch Risiko blockiert
0
Einrichtung erforderlich
0
Produktion
0

Noch keine Agent-Ergebnisdaten. Der erste Lauf kann Erfolg, Einrichtungsbedarf, Risikoblockaden, Fehler oder Irrelevanz über /api/agent/outcome melden.

Installieren

Zum Agent-Workflow hinzufügen

Kostenlos und Open Source. Bericht vor der Installation in Produktions-Agents prüfen.

Wachstums-Loop

Share-Kit

X

Szenariobasierter Entwurf für discriminated-unions, bereit für einen manuellen X-Post.

Kuratorenhinweis
A practical pick for source-backed research:

discriminated-unions: Apply, review, and explain discriminated unions in TypeScript. Use automatically for tasks involving mutually exclusive var...

780 stars

https://www.openagentskill.com/skills/mkosir-discriminated-unions?ref=x
X-Entwurf öffnen
Optionale Antwort mit Installationsbefehl
Listing + install path for discriminated-unions:
https://www.openagentskill.com/skills/mkosir-discriminated-unions?ref=x

Install: npx skills add mkosir/typescript-style-guide --skill discriminated-unions
Antwortentwurf öffnen

Quelle des Eintrags

Registry-indexiert

Beanspruchbar

Dieser Eintrag wurde aus öffentlichen Quellen indexiert und ist erst nach Genehmigung eines Maintainer-Anspruchs offiziell.

Ersteller
mkosir
Indexiert von
OpenAgentSkill Community-Index

Die Zuordnung verlinkt auf das öffentliche Repository oder Creator-Profil. Creator können den Eintrag beanspruchen, um Eigentümersignale zu aktualisieren.

Diesen Skill beanspruchen

Eigentümeranspruch

Diesen Skill-Eintrag beanspruchen

Dieser Registry-indexiert-Eintrag wird mkosir zugeschrieben, ist aber noch nicht offiziell markiert. Beanspruche ihn, um ein verifiziertes Eigentümersignal hinzuzufügen und künftige Launch-, Installations- und Audit-Updates vertrauenswürdiger zu machen.

Creator-Backlink-Kit

Evidenz-Badges in deine README einfügen

Zeige den kanonischen Eintrag, aktuelle Vertrauens- und Audit-Signale sowie echte Agent-Proven-Evidenz dort, wo Entwickler das Repository bewerten.

[![Listed on OpenAgentSkill](https://www.openagentskill.com/api/badge/mkosir-discriminated-unions?metric=listed&label=Listed)](https://www.openagentskill.com/skills/mkosir-discriminated-unions)
[![OpenAgentSkill Trust](https://www.openagentskill.com/api/badge/mkosir-discriminated-unions?metric=trust&label=Trust)](https://www.openagentskill.com/skills/mkosir-discriminated-unions)
[![OpenAgentSkill Audit](https://www.openagentskill.com/api/badge/mkosir-discriminated-unions?metric=audit&label=Audit)](https://www.openagentskill.com/skills/mkosir-discriminated-unions/audit)
[![Agent Proven](https://www.openagentskill.com/api/badge/mkosir-discriminated-unions?metric=proven&label=Agent%20Proven)](https://www.openagentskill.com/skills/mkosir-discriminated-unions)

Autor

M

mkosir

@mkosir

Plattform-Fit

Gesundheitssignale

GitHub-Stars
780
Qualitätswert
44/100
Letzter GitHub-Push
23. Aug. 2026
Framework-Hinweise
Unbekannt
OpenAgentSkill-Aufrufe
2
Installationskopien
0
Externe Klicks
0

Community-Signal

Teile mit, ob dieser Skill für deinen Agent-Workflow nützlich ist. Zusammengefasstes Feedback verbessert das Ranking im Laufe der Zeit.

Vertrauen & Sicherheit

Vor Installation prüfen

77
  • GitHub-Akzeptanz780 GitHub-StarsInfo
  • Star-/Fork-Aktivität780 Stars und 37 Forks; Issue-Aktivität ist in den aktuellen Metadaten nicht verfügbarInfo
  • Aktuelle WartungHeute gepushtBestanden
  • LizenzklarheitMITBestanden
  • README/SKILL.md-VollständigkeitMetadaten enthalten ausreichend Nutzungs- und Workflow-KontextBestanden
  • Abhängigkeits-/Laufzeitrisikonetwork or browser surfaceBestanden