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.
供給アセットの概要
リサーチとナレッジ作業
Deep research, source comparison, literature review, RAG, knowledge search, and reports.
シナリオ
リサーチ Agent
I need my agent to research a topic, compare sources, and produce a concise report.
Agent 適合
Claude Code + CLI + Codex
Codex、Claude Code、Cursor、CLI、またはカスタム Agent に対応します。
インストール
準備完了
npx skills add mkosir/typescript-style-guide --skill discriminated-unions
メンテナンス
新しい
本日プッシュ
リスク
試用可
Quality score needs review
GitHub 品質
780
76/100 品質 · 82/100 信頼
対象タグ
レビュー注記
Quality score needs review
Agent 導入スコアカード
信頼、監査、インストール準備状況を一目で確認
公開リポジトリのメタデータ、OpenAgentSkill のレビューシグナル、保守の鮮度、インストール準備状況を組み合わせたスコアです。候補選定の目安であり、人によるレビューの代替ではありません。
品質
強い本番ワークフローの候補に値する堅実な選択肢です。
信頼
レビュー後にインストール有望な候補ですが、Agent は実行前に監査メモ、インストールポリシー、成果エビデンスを確認する必要があります。
監査
試用可インストール準備、安全メタデータ、保守、採用リスクの機械可読なレビュー。
OpenAgentSkill Trust Score v5
インストール前に人のレビュー
人による確認またはサンドボックス検証後に第一候補として使用します。
スター
GitHub スター 780
リポジトリ活動
スター 780、フォーク 37
メンテナンス
本日プッシュ
ライセンス
MIT
インストール
npx skills add mkosir/typescript-style-guide --skill discriminated-unions
インストール安全性
標準パッケージまたはランタイムのインストールパス
権限範囲
filesystem or document access, network or browser access
Agent の成果
Agent の成果データはまだありません
ドキュメント
README/SKILL.md の文脈が十分です
リスク概要
低いメタデータリスク
- Quality score needs review
インストール準備状況
インストールパスを利用可能
- インストールパスを利用できます
- リポジトリの根拠を利用できます
- ライセンスが明示されています
- Agent-Proven の成果エビデンスはまだありません
Agent 可読メタデータ
このスキルの機械可読な判断データ。
このブロックまたは埋め込み JSON を使い、Agent がこのスキルをインストールすべきか、代替を選ぶべきか、先に人のレビューを求めるべきかを判断できます。
適したタスク
- コーディング Agent ワークフロー
- Claude Code チーム
- GitHub 採用シグナルを重視するチーム
- Inspect source files
適した Agent
インストール判断
- コマンド
- npx skills add mkosir/typescript-style-guide --skill discriminated-unions
- ポリシー
- レビュー
- 人によるレビュー
- はい
信頼とリスク
- 信頼
- 77/100
- 監査
- 85/100
- リスクレベル
- 試用可
成果ループ
- エンドポイント
- /api/agent/outcome
- イベント ID
- resolve
- 成果
- 5
インストールコマンド
npx skills add mkosir/typescript-style-guide --skill discriminated-unions使わない場合
- ベンダー提供の SLA が必要なチーム
- 内部セキュリティレビューのない高コンプライアンス環境
- 現在のメタデータに重大なリスクシグナルはありません
- Quality score needs review
- Production credentials, payments, or irreversible account changes without explicit human review
Agent セーフティ v2
69/100 · インストール前にレビュー
公開メタデータに高リスクな権限ヒントはなく、監査と安全性のシグナルは良好です。
監査ページを確認してから、サンドボックスのワークフローで Agent のインストールを許可してください。
中
ネットワークアクセス
Skill はリモートページ、API、リポジトリ、外部サービスにアクセスする可能性があります。
中
ファイルシステムアクセス
Skill はプロジェクトファイル、ドキュメント、生成物、ローカルワークスペース状態を読み書きする可能性があります。
- Quality score needs review
インストール先
Agent ワークフローにこのスキルをインストール
公開インストールエンドポイントからコマンド、安全チェックリスト、対象プロンプト、正規リンクを取得します。
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 解決プラン
インストール前に Agent に適合性を検証させます。
Resolve API は第一候補、代替、安全ポリシー、監査メモ、インストール先、Agent がそのまま使えるプロンプトを返します。
JSON を開く
/api/agent/resolve?task=Use%20discriminated-unions%20for%20an%20agent%20workflow&agent=codex&max_risk=medium
Resolve テキスト
/api/agent/resolve?task=Use%20discriminated-unions%20for%20an%20agent%20workflow&agent=codex&max_risk=medium&format=text
インストール引き継ぎ
/api/skills/mkosir-discriminated-unions/install
Agent が確認すべきこと
- Resolve API でタスク適合と代替を確認。
- 監査・信頼スコアと安全ポリシーの警告を確認。
- Codex、Claude Code、Cursor、CLI のインストール先互換性を確認。
プロンプトをコピー
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 引き継ぎ
別のディレクトリではなく、インストール経路を Agent に渡します。
公開インストールエンドポイントからコマンド、安全チェックリスト、対象プロンプト、正規リンクを取得します。
インストール引き継ぎ
/api/skills/mkosir-discriminated-unions/install
LLM テキスト形式
/api/skills/mkosir-discriminated-unions/install?format=text
代替を探す
/api/skills/search?q=discriminated-unions&limit=3
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-unionsRegistry メタデータ
自動スキル選択用の Agent 可読プロファイル。
Registry API 経由で判断、信頼、監査、ユースケース、インストールのシグナルを提供し、UI をスクレイピングせずに Agent が順位付けできます。
Agent 判断パネル
コーディング Agent 向けの第一候補
有力候補として扱い、自分の Agent スタックで README とインストール経路を検証してください。
スタック内の役割
第一候補
主な適合
コーディング Agent
信頼ラベル
本番対応
インストールパス
コマンド準備済み
使う場面
- コーディング Agent ワークフロー
- Claude Code チーム
- GitHub 採用シグナルを重視するチーム
根拠
- GitHub スター 780
- 最近のリポジトリ活動
- インストールコマンドまたは GitHub リポジトリが利用可能
- 品質プロファイル 76/100
- OpenAgentSkill エンゲージメント 2 件
先にレビュー
- 現在のメタデータに重大なリスクシグナルはありません
実装パス
- 1サンドボックスの Agent にインストールし、コーディング Agent タスクを一度最初から最後まで実行します。
- 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.
信頼プロファイル
レビュー後にインストール
有望な候補ですが、Agent は実行前に監査メモ、インストールポリシー、成果エビデンスを確認する必要があります。
GitHub 採用度
情報GitHub スター 780
スター/フォーク活動
情報スター 780、フォーク 37; 現在のメタデータでは Issue 活動を利用できません
最近のメンテナンス
合格本日プッシュ
ライセンスの明確さ
合格MIT
良いシグナル
- AI レビュー承認済み
- インストールパスを利用できます
- リポジトリの根拠を利用できます
- 最近保守されたリポジトリ
- 意味のある GitHub 採用シグナル
- インストールコマンドに明確な高リスクパターンはありません
- 成果ループは準備済みですが、最初の実行が必要です
インストール前にレビュー
- Quality score needs review
- 実際の Agent 成果レポートはまだありません
- 無人インストールの前に人によるレビューが必要です
推奨アクション
人による確認またはサンドボックス検証後に第一候補として使用します。
品質プロファイル
強い Agent ワークフロー向けの候補
本番ワークフローの候補に値する堅実な選択肢です。
ワークフロー適合
このスキルを使うシナリオ
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.
ワークフロー適合
完全なワークフローに追加
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.
代替候補
インストール前に比較
このタスクに適する可能性のある類似スキル。
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
概要
--- 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 -->
技術詳細
- バージョン
- 1.0.0
- ライセンス
- MIT
- 最終更新
- 2026年8月23日
- 公開日
- 2026年8月23日
判断の要約
第一候補
GitHub スター 780
Agent 実証エビデンス
Agent 実証エビデンス
Resolve、レビュー、インストール、限定実行後の成果レポート。
- 成功率
- —
- 直近の失敗
- —
- 成果
- 0
- 出力品質
- —
- 失敗
- 0
- 非該当
- 0
- インストール数
- 0
- リスクによりブロック
- 0
- 設定が必要
- 0
- 本番
- 0
Agent の実行結果はまだありません。最初の実行では /api/agent/outcome を通じて成功、設定要件、リスクによるブロック、失敗、非該当を報告できます。
成長ループ
共有キット
discriminated-unions 用のシナリオベース草案です。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
任意:インストールコマンド付きの返信
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
掲載元
Registry により登録
この掲載は公開ソースから登録されており、メンテナー申請が承認されるまで公式として表示されません。
- 作成者
- mkosir
- インデックス作成者
- OpenAgentSkill コミュニティインデックス
帰属は公開リポジトリまたは作成者プロフィールにリンクされています。作成者は掲載を申請して所有権シグナルを更新できます。
このスキルを申請所有者の申請
このスキル掲載を申請
この Registry により登録 掲載は mkosir に帰属していますが、まだ公式として表示されていません。申請すると、確認済み所有者シグナルが追加され、今後の公開、インストール、監査更新の信頼性が高まります。
クリエイター被リンクキット
README にエビデンスバッジを追加
開発者がリポジトリを評価する場所で、正規掲載、現在の信頼・監査シグナル、実際の Agent-Proven エビデンスを表示します。
[](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)作者
mkosir
@mkosir
プラットフォーム適合
健全性シグナル
- GitHub スター
- 780
- 品質スコア
- 44/100
- 最終 GitHub プッシュ
- 2026年8月23日
- フレームワークのヒント
- 不明
- OpenAgentSkill 閲覧数
- 2
- インストールコピー数
- 0
- 外部クリック
- 0
コミュニティシグナル
このスキルが Agent ワークフローに役立つかを共有してください。集約されたフィードバックがランキングを改善します。
信頼と安全性
レビュー後にインストール
- GitHub 採用度GitHub スター 780情報
- スター/フォーク活動スター 780、フォーク 37; 現在のメタデータでは Issue 活動を利用できません情報
- 最近のメンテナンス本日プッシュ合格
- ライセンスの明確さMIT合格
- README/SKILL.md の完全性メタデータには十分な利用・ワークフロー文脈があります合格
- 依存関係/ランタイムのリスクnetwork or browser surface合格
関連スキル
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 スターAcademic Research Skills
Academic Research Skills for Claude Code: research → write → review → revise → finalize
38.4K スターGPT Researcher
Run autonomous deep research over web and local sources
28.0K スターDeepResearch
Tongyi Deep Research, the Leading Open-source Deep Research Agent
19.8K スター