01
It starts by itself
TypeScript changes. Runs in GitHub Actions or Claude Code routine.
- ↻ TypeScript changes
push touching .ts or .tsx files
Invalid states removed from the code.
Install the Discriminated Unions skill and make it a habit: follow https://gethabit.dev/skills/mkosir/typescript-discriminated-unions.md
4K installs784 starsMIT licenceSource on GitHub ↗

Discriminated Unions
by mkosir · 4K installs
The skill
The typescript-discriminated-unions skill applies, reviews and explains discriminated unions in TypeScript to model mutually exclusive variants, prevent invalid states and enforce exhaustiveness.
Only when you ask.
The habit
Invalid states removed from the code.
↻ Runs by itselfTypeScript changes
When does it start? How does it check its work? What does it remember?
Stops after one change set per run, with at most 2 fix retries.
Your agent inspects the repository's conventions and config, which take precedence over the guidance.
It finds types where optional properties or boolean flags hide mutually exclusive variants.
It suggests a discriminated union with a shared literal discriminator per variant.
It leaves properties optional where they may independently be absent and does not force a union.
It confirms switches handle every variant via the ESLint rule.
It compiles with tsc and records the findings.
It writes only in its own folder and asks you before anything goes out.
Read both lists. If the left one sounds like you, the Discriminated Unions skill helps.
No. It uses a discriminated union only for mutually exclusive variants that need different data, not when a value simply changes.
No. Explicit repository conventions take precedence over this opinionated guidance.
Copy the prompt at the top into your agent. It installs the skill from mkosir/typescript-style-guide and sets up the habit. Or run npx skills add mkosir/typescript-style-guide --skill typescript-discriminated-unions.
Yes. It is published under MIT. Habit is free too.
Install the Discriminated Unions skill and make it a habit: follow https://gethabit.dev/skills/mkosir/typescript-discriminated-unions.md
All mkosir skills →More code skills →
Works in
Made by mkosir, published under MIT. Habit links to the original and never changes it. Is this your skill?