Skip to content
Back to skills

Typescript Best Practices

ASecurity

TypeScript grounding for type-system discipline: discriminated unions over flags, satisfies, parse-don't-validate at boundaries, branded primitives, no non-null assertions on external data.

  • 41,149 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 10, 2026
ai-agentstypescriptgitapi

Works with

  • cursor
  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 10, 2026

npx -y skills add Yeachan-Heo/oh-my-claudecode --skill typescript-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Typescript Best Practices?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Typescript Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/yeachan-heo-typescript-best-practices/badge)](https://www.skillsdirectory.com/skills/yeachan-heo-typescript-best-practices)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: typescript-best-practices
description: "TypeScript grounding for type-system discipline: discriminated unions over flags, satisfies, parse-don't-validate at boundaries, branded primitives, no non-null assertions on external data."
aliases: []
metadata:
  credits:
    type-discipline: pstack
    author: Lauren Tan
    url: "https://github.com/cursor/plugins/tree/main/pstack"
    port: pstack-claude
    port-author: Michael Denyer
    port-url: "https://github.com/michael-denyer/pstack-claude"
---

# TypeScript Best Practices

The type system is the cheapest place to make illegal states unrepresentable
(`principles` skill, Type system discipline). Concrete forms:

- **Discriminated unions over boolean flags.** `type Ev = {kind:'click'; x:number} | {kind:'focus'}` — not `{isClick:boolean; x?:number}`. Exhaustive `switch` on `kind` turns missing cases into compile errors.
- **`satisfies` for configuration literals.** `{...} satisfies Config` keeps literal inference while checking the shape.
- **Parse, don't validate, at boundaries.** External data (JSON, env, CLI args, API responses) passes through one parsing function returning a typed result; downstream code takes the parsed type, never `any` re-cast. `unknown` in, typed out.
- **Brand primitives that carry meaning.** `type SessionId = string & {__brand:'SessionId'}` when mixing two `string`s is a realistic bug.
- **No non-null assertions on external data.** `!` is allowed only where a check on a previous line proves the value; at boundaries it is a runtime crash with compile-time approval.
- **Return types that prevent misuse.** A function that can fail returns a result union, not `T` plus a thrown maybe; callers must handle both arms to compile.
- **`readonly` by default on shared shapes**, mutation as an explicit opt-in.

## Reviewing

When reviewing TS, the question per diff hunk is not "does it compile" but
"which illegal state did this type just permit" — flag flags-over-unions,
boundary `any`s, and unbranded overlapping primitives.

## Rules

- Discipline applies at the boundary and the domain model; inside a single
  function, pragmatism wins.
- Never introduce a type abstraction with one caller and no second one
  coming (`minimal-code-discipline`).

Files in this skill

  • SKILL.md2.2 KB
  • references/patterns.md2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.