typescript-best-practices
What it does
The skill gives rules for writing reliable TypeScript code. It is for developers who want fewer type errors and fewer hidden crashes.
When to use it
- ✓When you ask the agent to write or edit TypeScript or TSX files.
- ✓When you want unsafe type casts or loose types removed from your code.
- ✓When you want outside data checked before the code relies on it.
Skill link
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/typescript-best-practices/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Clean up the types in this TypeScript file so it does not rely on unsafe casts.”
5 new skills a week. 1 minute to read.
How it works
The agent follows a set of rules, such as using labeled variants, using unknown for outside data, and checking data with a schema before trusting its type. The rules keep impossible states out of the code.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
TypeScript best practices
Apply the type-system-discipline principle skill first.
| Rule | Summary |
|---|---|
| Discriminated unions | Model variants with a kind literal discriminant so impossible states can't be represented. No optional-field bags. |
| Branded types | Brand primitives with & { readonly __brand: "X" } so they can't be mixed up. Validate once at the boundary. A brand comes from a verifying type guard (input is AgentId), never from as. |
| Constructive modeling | Build the shape so the illegal value can't be constructed. [T, ...T[]] for non-empty, [T, T][] for even length, start plus duration for a range. Not a runtime guard, not a wish for refinement types. |
| Simplest total type | Keep T[] while every operation on it stays total. Strengthen to NonEmpty<T> only where the loose type forces !, a cast, or a "should never happen" throw. |
unknown over any |
External data is unknown. |
| Schemas before guards | Before hand-writing a property-by-property type guard, use the repository's runtime schema library and infer the type from the schema, such as z.infer. |
No as casts |
Every as is a runtime crash waiting. Cast only after validation. |
| Narrowing hierarchy | Discriminant switch > in operator > typeof/instanceof > user-defined type guard > as. |
| Type guards | Must verify the claim. A lying guard is worse than as because the bug hides behind a name that says it's safe. Name them isX or hasX. |
| Exhaustiveness | Inline const _exhaustive: never = x; in default arms so the compiler errors when a new variant is added. |
satisfies over as |
Validates the value without widening literal types. |
| Boundary validation | Parse where data crosses in, into a named domain type. Record<string, unknown> (however spelled) stops at that parse. Trust types inside. See the boundary-discipline principle skill. |
| Schema-derived types | Reach for Pick/Omit/Parameters/ReturnType/Awaited/typeof before declaring a new interface. |
| Object args | Pass objects, not positional, so argument order is self-documenting. Skip on hot paths (per-frame render, tokenizers, parsers). |
| Real tests | Don't mock what you can run. Prefer the framework's real test primitives with leak/disposable checks, and verify UI in a running build. Mock only what you can't run locally. |
| Structured telemetry | Prefer structured logger diagnostics with enough context to debug from an id. No console.log in shipped code. |
Examples: references/patterns.md.
FAQ
Does it work for plain JavaScript files?
The rules are for TypeScript files, meaning .ts and .tsx.
What is a branded type?
A type that marks a value, such as an ID, so it cannot be mixed up with a different value.
Why avoid as casts?
A cast tells the compiler to trust a value without checking it, so the code can fail at runtime.
Details
Original description by the author
TypeScript best practices. Use when reading or editing any .ts or .tsx file.
repo: cursor/plugins
Popularity
- GitHub stars
- 15k
- Ranking position
- #11002
- License
- —
- Updated
- 10/31/2026
Comments
- …
More skills from this repository
advisor
15kLets your agent consult a stronger second model at key checkpoints, such as before a big decision or when stuck on an error, if you turn it on.
check-agent-compatibility
15kRuns a full check of whether AI coding agents can start, verify and document a repository, and returns one compatibility score with the main issues.
cli-for-agents
15kTeaches your agent to design or review command-line tools so AI agents can run them without prompts, with clear help text and examples.
continual-learning
15kKeeps your AGENTS.md notes up to date by handing the work of reviewing past chats to a dedicated memory updater.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.