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.
Profil aset
Riset dan pekerjaan pengetahuan
Deep research, source comparison, literature review, RAG, knowledge search, and reports.
Skenario
Agent riset
I need my agent to research a topic, compare sources, and produce a concise report.
Kecocokan Agent
Claude Code + CLI + Codex
Cocok untuk Codex, Claude Code, Cursor, CLI, atau Agent khusus.
Pasang
Siap
npx skills add mkosir/typescript-style-guide --skill discriminated-unions
Pemeliharaan
Terkini
Diperbarui hari ini
Risiko
Aman untuk dicoba
Quality score needs review
Kualitas GitHub
780
76/100 Kualitas · 82/100 Kepercayaan
Tag cakupan
Catatan ulasan
Quality score needs review
Kartu adopsi Agent
Kepercayaan, audit, dan kesiapan pemasangan dalam sekali lihat
Skor ini menggabungkan metadata repositori publik, sinyal ulasan OpenAgentSkill, kebaruan pemeliharaan, dan kesiapan pemasangan. Ini adalah sinyal shortlist, bukan pengganti peninjauan manusia.
Kualitas
KuatSolid option that is likely worth shortlisting for production workflows.
Kepercayaan
Tinjau sebelum memasangSinyal shortlist yang baik, tetapi Agent harus meninjau catatan audit, kebijakan pemasangan, dan bukti hasil sebelum menjalankannya.
Audit
Aman untuk dicobaTinjauan yang dapat dibaca mesin tentang kesiapan pemasangan, metadata keamanan, pemeliharaan, dan risiko adopsi.
Trust Score OpenAgentSkill v5
Tinjauan manusia sebelum pemasangan
Gunakan sebagai kandidat utama setelah tinjauan manusia atau sandbox.
Star
780 star GitHub
Aktivitas repositori
780 star dan 37 fork
Pemeliharaan
Diperbarui hari ini
Lisensi
MIT
Pasang
npx skills add mkosir/typescript-style-guide --skill discriminated-unions
Keamanan pemasangan
Jalur pemasangan paket atau runtime standar
Cakupan izin
filesystem or document access, network or browser access
Hasil Agent
Belum ada data hasil Agent
Dokumentasi
Konteks README/SKILL.md kuat
Ringkasan risiko
Risiko metadata rendah
- Quality score needs review
Kesiapan pemasangan
Jalur pemasangan tersedia
- Jalur pemasangan tersedia
- Bukti repositori tersedia
- Lisensi dinyatakan
- Belum ada bukti hasil Agent-Proven
Metadata yang dapat dibaca Agent
Data keputusan yang dapat dibaca mesin untuk skill ini.
Gunakan blok ini atau JSON tersemat untuk memutuskan apakah Agent perlu memasang skill ini, memilih alternatif, atau meminta tinjauan manusia terlebih dahulu.
Tugas yang sesuai
- alur kerja Agent pemrograman
- Tim Claude Code
- Tim yang menghargai sinyal adopsi GitHub
- Inspect source files
Agent yang sesuai
Keputusan pemasangan
- Perintah
- npx skills add mkosir/typescript-style-guide --skill discriminated-unions
- Kebijakan
- Tinjau
- Tinjauan manusia
- Ya
Kepercayaan dan risiko
- Kepercayaan
- 77/100
- Audit
- 85/100
- Tingkat risiko
- Aman untuk dicoba
Lingkar hasil
- Endpoint
- /api/agent/outcome
- ID event
- resolve
- Hasil
- 5
Perintah pemasangan
npx skills add mkosir/typescript-style-guide --skill discriminated-unionsJangan gunakan ketika
- Tim yang membutuhkan SLA dengan dukungan vendor
- Lingkungan berkompliansi tinggi tanpa tinjauan keamanan internal
- No major risk signals from current metadata
- Quality score needs review
- Production credentials, payments, or irreversible account changes without explicit human review
Skill alternatif
Last30days Skill
53.5K Star
npx skills add mvanhorn/last30days-skill -g
Skill alternatif
Academic Research Skills
38.4K Star
npx skills add Imbad0202/academic-research-skills
Skill alternatif
GPT Researcher
28.0K Star
npx skills add assafelovic/gpt-researcher
Skill alternatif
DeepResearch
19.8K Star
npx skills add Alibaba-NLP/DeepResearch
Keamanan Agent v2
69/100 · Tinjau sebelum memasang
Sinyal audit dan keamanan baik tanpa petunjuk izin berisiko tinggi dalam metadata publik.
Tinjau halaman audit, lalu izinkan pemasangan Agent dalam alur kerja sandbox.
Sedang
Akses jaringan
Skill kemungkinan mengambil halaman jarak jauh, API, repositori, atau layanan eksternal.
Sedang
Akses sistem file
Skill dapat membaca atau menulis file proyek, dokumen, artefak yang dihasilkan, atau status workspace lokal.
- Quality score needs review
Target pemasangan
Pasang skill ini di alur Agent Anda
Gunakan endpoint publik untuk mengambil perintah, checklist keamanan, prompt target, dan tautan kanonis.
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-unionsRencana resolusi Agent
Biarkan Agent memverifikasi kecocokan sebelum memasang.
API Resolve mengembalikan skill utama, alternatif, kebijakan keamanan, catatan audit, target pemasangan, dan prompt siap pakai.
Buka JSON
/api/agent/resolve?task=Use%20discriminated-unions%20for%20an%20agent%20workflow&agent=codex&max_risk=medium
Teks Resolve
/api/agent/resolve?task=Use%20discriminated-unions%20for%20an%20agent%20workflow&agent=codex&max_risk=medium&format=text
Serah-terima pemasangan
/api/skills/mkosir-discriminated-unions/install
Agent harus memeriksa
- 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.
Salin prompt
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.Serah-terima Agent
Berikan jalur pemasangan kepada Agent, bukan direktori lain.
Gunakan endpoint publik untuk mengambil perintah, checklist keamanan, prompt target, dan tautan kanonis.
Serah-terima pemasangan
/api/skills/mkosir-discriminated-unions/install
Format teks LLM
/api/skills/mkosir-discriminated-unions/install?format=text
Cari alternatif
/api/skills/search?q=discriminated-unions&limit=3
Prompt Agent
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-unionsMetadata Registry
Profil yang dapat dibaca Agent untuk pemilihan skill otomatis.
API Registry menyediakan sinyal keputusan, kepercayaan, audit, use case, dan pemasangan tanpa mengikis UI.
Manifest
/api/registry/manifest/mkosir-discriminated-unions
Teks LLM
/api/registry/manifest/mkosir-discriminated-unions?format=text
Alias pemasangan
/api/registry/install/mkosir-discriminated-unions
Rekomendasikan
/api/registry/recommend?task=Use%20discriminated-unions%20in%20an%20agent%20workflow&limit=3
Kecocokan Agent
Agent pemrograman
Tag use case
Platform
Claude Code
Laporan audit
Aman untuk dicoba · 85/100
Tinjauan yang dapat dibaca mesin tentang kesiapan pemasangan, metadata keamanan, pemeliharaan, dan risiko adopsi.
Panel keputusan Agent
Pilihan utama untuk Agent pemrograman
Use this as a leading candidate, then validate the README and install path in your own agent stack.
Peran di stack
Pilihan utama
Kecocokan utama
Agent pemrograman
Label kepercayaan
Siap produksi
Jalur pemasangan
Perintah siap
Gunakan saat
- alur kerja Agent pemrograman
- Tim Claude Code
- Tim yang menghargai sinyal adopsi GitHub
Bukti
- 780 star GitHub
- recent repository activity
- install command or GitHub repo available
- profil kualitas 76/100
- 2 event interaksi OpenAgentSkill
tinjau dulu
- No major risk signals from current metadata
Jalur implementasi
- 1Pasang di Agent sandbox dan jalankan satu tugas Agent pemrograman dari awal hingga akhir.
- 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.
Profil kepercayaan
Tinjau sebelum memasang
Sinyal shortlist yang baik, tetapi Agent harus meninjau catatan audit, kebijakan pemasangan, dan bukti hasil sebelum menjalankannya.
Adopsi GitHub
Info780 star GitHub
Aktivitas star/fork
Info780 star dan 37 fork; aktivitas issue tidak tersedia dalam metadata saat ini
Pemeliharaan terbaru
LulusDiperbarui hari ini
Kejelasan lisensi
LulusMIT
Sinyal positif
- Tinjauan AI disetujui
- Jalur pemasangan tersedia
- Bukti repositori tersedia
- Repositori yang baru dipelihara
- Sinyal adopsi GitHub yang bermakna
- Perintah pemasangan tidak memiliki pola berisiko tinggi yang jelas
- Loop hasil siap tetapi membutuhkan eksekusi Agent nyata pertama
Tinjau sebelum memasang
- Quality score needs review
- Belum ada laporan hasil Agent nyata
- Tinjauan manusia diperlukan sebelum pemasangan tanpa pengawasan
Tindakan yang disarankan
Gunakan sebagai kandidat utama setelah tinjauan manusia atau sandbox.
Profil kualitas
Kuat kandidat untuk alur kerja Agent
Solid option that is likely worth shortlisting for production workflows.
Kecocokan alur kerja
Gunakan skill ini pada skenario berikut
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.
Kecocokan alur kerja
Tambahkan ke alur kerja lengkap
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.
Daftar alternatif
Bandingkan sebelum memasang
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
Ringkasan
--- 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 -->
Detail teknis
- Versi
- 1.0.0
- Lisensi
- MIT
- Pembaruan terakhir
- 23 Agu 2026
- Diterbitkan
- 23 Agu 2026
Ringkasan keputusan
Pilihan utama
780 star GitHub
Audit
Tinjauan pemasangan
Tinjauan pemasangan dan adopsi
- Keamanan
- 86/100
- Pemeliharaan
- 100/100
- Pasang
- 92/100
Bukti tervalidasi Agent
Bukti tervalidasi Agent
Laporan hasil setelah resolve, tinjau, pasang, dan satu eksekusi terbatas.
- Tingkat sukses
- —
- Kegagalan terbaru
- —
- Hasil
- 0
- Kualitas output
- —
- Gagal
- 0
- Tidak relevan
- 0
- Pemasangan
- 0
- Diblokir risiko
- 0
- Perlu penyiapan
- 0
- Produksi
- 0
Belum ada data hasil Agent. Eksekusi pertama dapat melaporkan keberhasilan, kebutuhan setup, blok risiko, kegagalan, atau tidak relevan melalui /api/agent/outcome.
Pasang
Tambahkan ke alur Agent
Gratis dan sumber terbuka. Tinjau laporan sebelum memasang pada Agent produksi.
Siklus pertumbuhan
Kit berbagi
Draf berbasis skenario untuk discriminated-unions, siap untuk posting manual di X.
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
Balasan opsional dengan perintah pemasangan
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
Sumber listing
Diindeks Registry
Listing ini diindeks dari sumber publik dan belum ditandai resmi hingga klaim pemelihara disetujui.
- Kreator
- mkosir
- Diindeks oleh
- Indeks komunitas OpenAgentSkill
Atribusi menautkan ke repositori publik atau profil kreator. Kreator dapat mengklaim listing untuk memperbarui sinyal kepemilikan.
Klaim skill iniKlaim pemilik
Klaim listing skill ini
Listing Diindeks Registry ini dikaitkan dengan mkosir, tetapi belum ditandai resmi. Klaim untuk menambahkan sinyal pemilik terverifikasi dan membuat pembaruan peluncuran, pemasangan, serta audit berikutnya lebih tepercaya.
Kit backlink kreator
Tambahkan badge bukti ke README Anda
Tampilkan listing kanonis, sinyal kepercayaan dan audit saat ini, serta bukti Agent-Proven nyata di tempat pengembang mengevaluasi repositori.
[](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)Penulis
mkosir
@mkosir
Tag
Kecocokan platform
Sinyal kesehatan
- Star GitHub
- 780
- Skor kualitas
- 44/100
- Push GitHub terakhir
- 23 Agu 2026
- Petunjuk framework
- Tidak diketahui
- Tampilan OpenAgentSkill
- 2
- Salinan pemasangan
- 0
- Klik keluar
- 0
Sinyal komunitas
Bagikan apakah skill ini bermanfaat untuk alur kerja Agent Anda. Masukan gabungan meningkatkan peringkat dari waktu ke waktu.
Kepercayaan & keamanan
Tinjau sebelum memasang
- Adopsi GitHub780 star GitHubInfo
- Aktivitas star/fork780 star dan 37 fork; aktivitas issue tidak tersedia dalam metadata saat iniInfo
- Pemeliharaan terbaruDiperbarui hari iniLulus
- Kejelasan lisensiMITLulus
- Kelengkapan README/SKILL.mdMetadata memuat konteks penggunaan dan alur kerja yang cukupLulus
- Risiko dependensi/runtimenetwork or browser surfaceLulus
Skill terkait
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 StarAcademic Research Skills
Academic Research Skills for Claude Code: research → write → review → revise → finalize
38.4K StarGPT Researcher
Run autonomous deep research over web and local sources
28.0K StarDeepResearch
Tongyi Deep Research, the Leading Open-source Deep Research Agent
19.8K Star