typescript-best-practices

Guide TypeScript project configuration and code review for type safety and maintainability.

5|Updated Oct 17, 2011
One-click install
npx skills add https://github.com/klen/dotfiles --skill typescript-best-practices-klen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-best-practices
Source: https://github.com/klen/dotfiles/tree/main/.config/opencode/skills/typescript-best-practices
Command: npx skills add https://github.com/klen/dotfiles --skill typescript-best-practices-klen

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on writing clean, type-safe, and maintainable TypeScript code, helping developers avoid common pitfalls and improve code quality.

Core Features & Use Cases

  • Type Safety: Enforces strict type checking and safe handling of null/undefined values.
  • Code Organization: Offers best practices for file naming, barrel exports, and project structure.
  • Function Design: Guides on explicit parameter types, single responsibility, and guard clauses.
  • Async Patterns: Details on error handling, parallel operations with Promise.all, and flattening async chains.
  • Use Case: When setting up a new TypeScript project or refactoring an existing one, use this Skill to ensure adherence to modern best practices for maximum reliability and maintainability.

Quick Start

Review the TypeScript best practices for configuring a new project.

Frequently Asked Questions about typescript-best-practices

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

FAQPage Schema
What are the best practices for type safety in TypeScript?

TypeScript best practices for type safety involve enforcing strict mode, leveraging type inference, and applying guard clauses to safely handle null, undefined, and unknown types.

How do I decide between using an interface vs a type alias in TypeScript?

Choosing between an interface and a type alias depends on your extension needs. This best practice guides you on when to use interfaces for declaration merging versus type aliases for complex union definitions.

What is the best way to handle async error handling and Promise chains in TypeScript?

The best way to handle async code is to flatten Promise chains and use Promise.all for parallel operations. You should also enforce explicit error handling patterns to maintain code reliability.

How do I configure a new TypeScript project for maintainability?

Configuring a maintainable TypeScript project requires setting up strict mode and organizing files with proper naming conventions. You should also use barrel exports and follow single responsibility principles for functions.

Why should I enable strict mode when writing TypeScript code?

You should enable strict mode in TypeScript to catch common bugs early and enforce robust type checking. It ensures safe handling of null and undefined values, significantly improving overall code quality.