typescript-best-practices

Applies TypeScript typing rules and code review practices when reading or editing .ts and .tsx files.

Updated Aug 28, 2026
One-click install
npx skills add https://github.com/jeremybrasher/grokbot-skills --skill typescript-best-practices-jeremybrasher
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: typescript-best-practices
Source: https://github.com/jeremybrasher/grokbot-skills/tree/main/collections/pstack/skills/typescript-best-practices
Command: npx skills add https://github.com/jeremybrasher/grokbot-skills --skill typescript-best-practices-jeremybrasher

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? TypeScript codebases accumulate unsafe patterns like any casts, lying type guards, and optional-field bags that hide bugs until runtime. This Skill enforces disciplined type-system practices whenever an agent reads or edits TypeScript files, and it refuses to guess when required inputs are missing. ## Core Features & Use Cases - Type-system discipline rules: Enforces discriminated unions, branded types, unknown over any, schema-derived types, and exhaustiveness checks via a structured rule table. - Intake and HOLD gates: Stops and reports missing inputs (no .ts/.tsx target, unreadable tsconfig) instead of inventing speculative types or rival house styles. - Cut-first defaults: Prefers existing project patterns and the smallest typing fix, refusing drive-by refactors and unrequested utility types. - Use Case: While editing a React component in a .tsx file, the Skill replaces an as cast with a zod schema parse at the boundary and adds an exhaustiveness check to a switch over a discriminated union. ## Quick Start Review the attached TypeScript file and apply type-system best practices, holding on anything that conflicts with the project tsconfig.

Frequently Asked Questions about typescript-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce TypeScript best practices during code edits?▼

Apply a rule set covering discriminated unions, branded types, `unknown` over `any`, and no `as` casts without prior validation. This Skill runs those rules whenever .ts or .tsx files are read or edited, citing observed files for every recommendation.

What is the best way to replace any types in TypeScript?▼

Treat external data as `unknown` and parse it at the boundary with a runtime schema library such as zod, inferring types via `z.infer`. Avoid `as` casts; validate first, then trust types inside the boundary.

Should I use discriminated unions or optional fields in TypeScript?▼

Use discriminated unions with a `kind` literal discriminant so impossible states cannot be represented. Optional-field bags allow invalid combinations; a discriminant switch with an exhaustiveness check makes the compiler error when a new variant is added.

Does this work with my existing project tsconfig?▼

Yes, the Skill reads the project's tsconfig and existing patterns before advising, and it holds rather than inventing a rival house style when advice would conflict with the stated configuration.

When should I not apply stricter TypeScript patterns?▼

Skip object-argument passing on hot paths like per-frame rendering or parsers, and keep `T[]` while every operation stays total. Strengthen to stricter types only where the loose type forces a non-null assertion, cast, or a should-never-happen throw.