discriminated-unions
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.
Asset-Profil
Recherche und Wissensarbeit
Deep research, source comparison, literature review, RAG, knowledge search, and reports.
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
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
StarkSolid option that is likely worth shortlisting for production workflows.
Vertrauen
Vor Installation prüfenGutes Shortlist-Signal, aber der Agent sollte Auditnotizen, Installationsrichtlinien und Ergebnisbelege vor der Ausführung prüfen.
Audit
Sicher zu testenMaschinenlesbare 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.
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.
Geeignete Aufgaben
- Coding-Agents-Workflows
- Claude-Code-Teams
- Teams, die GitHub-Adoptionssignale schätzen
- Inspect source files
Geeignete Agents
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-unionsNicht 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
Alternative
Last30days Skill
53.5K Stars
npx skills add mvanhorn/last30days-skill -g
Alternative
Academic Research Skills
38.4K Stars
npx skills add Imbad0202/academic-research-skills
Alternative
GPT Researcher
28.0K Stars
npx skills add assafelovic/gpt-researcher
Alternative
DeepResearch
19.8K Stars
npx skills add Alibaba-NLP/DeepResearch
Agent-Sicherheit v2
69/100 · Vor Installation prü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.
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.
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-unionsAgent-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.
JSON öffnen
/api/agent/resolve?task=Use%20discriminated-unions%20for%20an%20agent%20workflow&agent=codex&max_risk=medium
Resolve-Text
/api/agent/resolve?task=Use%20discriminated-unions%20for%20an%20agent%20workflow&agent=codex&max_risk=medium&format=text
Installationsübergabe
/api/skills/mkosir-discriminated-unions/install
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übergabe
/api/skills/mkosir-discriminated-unions/install
LLM-Textformat
/api/skills/mkosir-discriminated-unions/install?format=text
Alternativen finden
/api/skills/search?q=discriminated-unions&limit=3
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-unionsRegistry-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
/api/registry/manifest/mkosir-discriminated-unions
LLM-Text
/api/registry/manifest/mkosir-discriminated-unions?format=text
Installationsalias
/api/registry/install/mkosir-discriminated-unions
Empfehlen
/api/registry/recommend?task=Use%20discriminated-unions%20in%20an%20agent%20workflow&limit=3
Agent-Fit
Coding-Agents
Plattformen
Claude Code
Audit-Bericht
Sicher zu testen · 85/100
Maschinenlesbare Prüfung von Installationsbereitschaft, Sicherheitsmetadaten, Wartung und Akzeptanzrisiko.
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.
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
- 1Installieren Sie es in einem Sandbox-Agent und führen Sie eine Coding-Agents-Aufgabe vollständig aus.
- 2Compare output quality, latency, and failure behavior against at least one alternative.
- 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.
GitHub-Akzeptanz
Info780 GitHub-Stars
Star-/Fork-Aktivität
Info780 Stars und 37 Forks; Issue-Aktivität ist in den aktuellen Metadaten nicht verfügbar
Aktuelle Wartung
BestandenHeute gepusht
Lizenzklarheit
BestandenMIT
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.
Workflow-Eignung
Diese Skill in diesen Szenarien nutzen
Build and ship code
Coding agents
I need a coding agent that can understand a repository, edit code, and review pull requests.
Investigate faster
Research agents
I need my agent to research a topic, compare sources, and produce a concise report.
Automate repeated work
Workflow automation
I need my agent to automate a repeated workflow across tools and files.
Workflow-Eignung
Zum vollständigen Workflow hinzufügen
Inspect, patch, and verify code
Coding review agent
A workflow for software agents that inspect repositories, review pull requests, generate tests, and turn findings into shippable patches.
Find, compare, and synthesize
Research report agent
A workflow for agents that gather sources, compare claims, summarize long material, and draft useful research briefs.
Turn skills into distribution
Content growth agent
A workflow for turning newly indexed skills into SEO briefs, social drafts, comparison pages, and reusable publishing workflows.
Alternativen-Shortlist
Vor Installation vergleichen
Similar skills that may fit this task.
Last30days Skill
Research the last 30 days across Reddit, X, YouTube, Hacker News, Polymarket, GitHub, and the web, then synthesize a grounded brief for an AI agent.
Academic Research Skills
Academic Research Skills for Claude Code: research → write → review → revise → finalize
GPT Researcher
Run autonomous deep research over web and local sources
DeepResearch
Tongyi Deep Research, the Leading Open-source Deep Research Agent
Ü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
780 GitHub-Stars
Audit
Installationsprüfung
Installations- und Adoptionsprüfung
- Sicherheit
- 86/100
- Wartung
- 100/100
- Installieren
- 92/100
Von Agent belegte Evidenz
Von Agent belegte Evidenz
Ergebnisberichte nach Resolve, Prüfung, Installation und einem begrenzten Lauf.
- 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
Szenariobasierter Entwurf für discriminated-unions, bereit für einen manuellen X-Post.
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
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
Quelle des Eintrags
Registry-indexiert
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 beanspruchenEigentü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.
[](https://www.openagentskill.com/skills/mkosir-discriminated-unions)
[](https://www.openagentskill.com/skills/mkosir-discriminated-unions)
[](https://www.openagentskill.com/skills/mkosir-discriminated-unions/audit)
[](https://www.openagentskill.com/skills/mkosir-discriminated-unions)Autor
mkosir
@mkosir
Tags
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
- 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
Ähnliche Skills
Last30days Skill
Research the last 30 days across Reddit, X, YouTube, Hacker News, Polymarket, GitHub, and the web, then synthesize a grounded brief for an AI agent.
53.5K StarsAcademic Research Skills
Academic Research Skills for Claude Code: research → write → review → revise → finalize
38.4K StarsGPT Researcher
Run autonomous deep research over web and local sources
28.0K StarsDeepResearch
Tongyi Deep Research, the Leading Open-source Deep Research Agent
19.8K Stars