typescript-best-practices

Enforce TypeScript best practices for type imports, validation, and secure data handling.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/KJR020/dotfiles --skill typescript-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-best-practices
Source: https://github.com/KJR020/dotfiles/tree/main/home/dot_claude/skills/typescript-best-practices
Command: npx skills add https://github.com/KJR020/dotfiles --skill typescript-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides enterprise-grade TypeScript patterns and practices to improve type safety, security, and maintainable code. Use when writing TS, performing code reviews, or implementing robust error handling.

Core Features & Use Cases

  • Type Imports (CRITICAL): Always use type imports for TypeScript types to improve build performance and clarity.
  • Security Rules: Never expose sensitive data; use type guards and input validation to enforce safety.
  • Code Structure & Async Patterns: Early returns, modular composition, and disciplined async/Promise patterns.
  • Use Cases: Adopt these patterns when starting new TS projects or auditing existing code for quality and safety.

Quick Start

Install or apply these patterns in your project by following the examples and templates in this skill. Start by replacing regular imports with import type for your TypeScript types, enforce early returns, and add a small set of guard clauses to validate inputs.

Frequently Asked Questions about typescript-best-practices

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

FAQPage Schema
How do I improve TypeScript type safety and reduce defects in my codebase?

Type safety in TypeScript improves through enforcing best-practice patterns: use type imports for clarity and build performance, implement type guards for input validation, apply discriminated unions for exhaustive handling, and maintain explicit typing throughout. These patterns catch errors at compile time and reduce runtime defects.

What's the difference between regular imports and type imports in TypeScript?

Type imports use `import type` syntax to import only TypeScript types, never runtime values. Regular imports include both types and values. Type imports improve build performance by allowing the compiler to eliminate unused type-only imports and clarify intent in your code.

How do I implement secure error handling and input validation in TypeScript?

Secure error handling combines type guards for input validation, early returns to exit fast on invalid data, and parameterized queries to prevent injection attacks. Never expose sensitive data in error messages; validate all external input before processing and use TypeScript's type system to enforce safety constraints.

When should I use discriminated unions and exhaustiveness checking in TypeScript?

Discriminated unions organize related types with a shared literal field, enabling the compiler to narrow types safely. Exhaustiveness checking via `never` ensures all union cases are handled. Use these when modeling domain states or API responses to catch missing cases at compile time.

Can I apply TypeScript best practices to existing codebases, or only new projects?

TypeScript best practices apply to both new projects and existing codebases. Use them during code reviews, refactoring, and security hardening. Incrementally adopt patterns like type imports and early returns; start with high-risk or frequently-modified code to maximize impact.

What async and code-structure patterns does TypeScript best practices cover?

Best practices emphasize disciplined async patterns with Promise handling, early returns to reduce nesting, and modular composition for maintainability. These patterns simplify error propagation, improve readability, and make asynchronous code safer and easier to reason about.