typescript-best-practices

typescript-best-practices is a skill for Claude Code, Codex from monkilabs/opencastle. It costs 54 tokens per session (1,377 once invoked), scanned A, original, MIT.

A TypeScript guide for modelling data so invalid states are harder to represent. It covers unions, branded values, validation, type narrowing, and avoiding unsafe casts.

In plain words
What is it for?
Use it when designing domain types or refactoring TypeScript and TSX code, especially where optional fields, type casts, or external input are involved.
Why use it?
It helps the TypeScript compiler catch more mistakes and reduces runtime failures caused by unchecked external data or incorrect assumptions.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when designing domain types or refactoring TypeScript and TSX code, especially where optional fields, type casts, or external input are involved.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/monkilabs/opencastle/typescript-best-practices
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add monkilabs/opencastle --skill typescript-best-practices
Clone the repo
git clone --depth 1 https://github.com/monkilabs/opencastle

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for typescript-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/skills/monkilabs/opencastle/typescript-best-practices/github.svg)](https://agentmods.dev/skills/monkilabs/opencastle/typescript-best-practices)
Your own site
<a href="https://agentmods.dev/skills/monkilabs/opencastle/typescript-best-practices"><img src="https://agentmods.dev/badge/skills/monkilabs/opencastle/typescript-best-practices/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for typescript-best-practices

Your own site · 80×15
<a href="https://agentmods.dev/skills/monkilabs/opencastle/typescript-best-practices"><img src="https://agentmods.dev/badge/skills/monkilabs/opencastle/typescript-best-practices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 54 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,377 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00054 $0.01377
Opus 5.5 $0.00022 $0.00551
Sonnet 5.5 $0.00011 $0.00275
Haiku 4.5 $0.00005 $0.00138

Measured 23d ago against content hash 3b09b6c5c1c0, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

typescript-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 23d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

src/orchestrator/skills/typescript-best-practices/SKILL.md · 95 lines

How it starts

The opening of the file, as written. The whole thing — 95 lines — stays where its author put it; the contents beside it link to each section on GitHub.

TypeScript Best Practices

Make the illegal state unrepresentable, then let the compiler enforce it.

Rule Summary
Discriminated unions Model variants with a kind literal discriminant so impossible states cannot be represented. No optional-field bags.
Branded types Brand primitives with & { readonly __brand: 'X' } so they cannot be mixed up. Validate once at creation.
Constructive modeling Build the shape so the illegal value cannot be constructed. [T, ...T[]] for non-empty, [T, T][] for even length, start plus duration for a range. Not a runtime guard.
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. any disables type checking everywhere it touches.
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 is safe. Name them isX or hasX.
Exhaustiveness Inline const _exhaustive: never = x in default arms so the compiler errors when a 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> stops at that parse. Trust types inside; do not re-validate deep in call chains.
Schema-derived types Reach for Pick/Omit/Parameters/ReturnType/Awaited/typeof before declaring a new interface.
Object args Pass objects, not positional args, so argument order is self-documenting. Skip on hot paths: per-frame render, tokenizers, parsers.
Real tests Do not mock what you can run. Prefer real test primitives and verify UI in a running build. Mock only what you cannot run locally.
Structured telemetry Structured logger diagnostics with enough context to debug from an id. No console.log in shipped code.

External data is anything from RPC payloads, JSON.parse, postMessage, IPC, file contents, environment variables, or database results.

Read the full file on GitHub · 95 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 23d ago Changed · -9 tokens per session 3b09b6c5c1c0
  2. 1mo ago First seen · 95 lines · 63 tokens per session scan A 753fc87d6749

Subscribe to this mod's changes

typescript-best-practices is a skill published in the GitHub repository monkilabs/opencastle (80 stars, last pushed 7d ago), licensed MIT. It adds 54 tokens to every session and 1,377 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

python-patterns

Python development principles and decision-making. Framework selection, async patterns, type hints, and project structure.

DDS-Solutions/AI-TadPole-OS · 24 tokens

rust-pro

Master Rust 1.75+ with modern async patterns, advanced type system features, and production-ready systems programming. Expert in Tokio, Axum, and zero-cost abstractions.

DDS-Solutions/AI-TadPole-OS · 39 tokens

tauri-pro

Master Tauri v1/v2 desktop development with Rust commands, IPC bridge, security capabilities, window state, and event bus.

DDS-Solutions/AI-TadPole-OS · 30 tokens

angular-shared-libraries

Structuring reusable Angular code across an app or Nx/Angular-CLI workspace — shared reactive-forms building blocks (form-group factories, centralized validators) and a generic typed paged/sortable/filterable DataTableComponent, extracted into proper workspace libraries with clean public APIs instead of duplicated per…

AgenticPawan/FullStack-Pilot · 66 tokens

angular-coding-standards

General Angular coding-standards enforcement — naming conventions, standalone-first architecture (v17+), service extraction for business logic, strict TypeScript compiler options, barrel-file risk, and signal-based input()/output() adoption (v17.1+). Version-gated checks read .claude/pilot/stack-profile.json…

AgenticPawan/FullStack-Pilot · 89 tokens

nodejs-devtools

TypeScript, ESLint, Prettier. Use when the project needs this capability or the user / team manifest asks for it. Use for specialized nodejs-devtools work when listed in TEAM.yaml or explicitly requested.

rogue-dev-studio/ai-agents-rogue · 51 tokens