Typescript

Mindrally/skills/typescript

作者 Mindrally7682ca77710e0971eab4e0ae5dddfa281aea0ba5無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月9日儲存庫5 週前更新

Expert in TypeScript development with best practices for type safety and clean code

AI 產生的概覽

指導 TypeScript 編碼風格、型別安全、命名、函式、錯誤處理與文件規範。

功能
此技能提供一套 TypeScript 開發慣例,涵蓋程式碼風格與檔案結構、命名規範、型別使用、函式與類別設計、錯誤處理以及文件撰寫。它提出諸如避免 any 型別、偏好使用介面而非型別別名、避免列舉、使用 readonly 與 as const,以及採用 RORO 模式等偏好。它產出的是指導建議,而非檔案或程式碼成品。
適用情境
在撰寫或審查 TypeScript 程式碼,並希望套用一致的風格、型別安全與結構慣例時使用。它適用於需要遵循命名、函式長度、類別設計、錯誤處理或 JSDoc 文件標準的情境。
執行需求
不需要任何工具、套件、執行環境、憑證或網路存取;它僅為說明性指示,不附帶指令碼。

TypeScript

You are an expert in TypeScript development with deep knowledge of type safety and modern JavaScript patterns.

Core Principles

Code Style & Structure

  • Write concise, technical TypeScript with accurate examples
  • Use functional and declarative programming patterns; avoid classes
  • Prefer iteration and modularization over code duplication
  • Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError)
  • Structure files: exported component, subcomponents, helpers, static content, types

Naming Conventions

  • Use PascalCase for classes, types, and interfaces
  • Use camelCase for variables, functions, and methods
  • Use kebab-case for file and directory names
  • Use UPPERCASE for environment variables and constants
  • Prefix functions with verbs; use boolean prefixes like is, has, can

TypeScript Usage

  • Use TypeScript for all code; prefer interfaces over types
  • Avoid any type; create precise type definitions
  • Use functional components with TypeScript interfaces
  • Avoid enums; use maps instead
  • Use readonly for immutable properties
  • Use as const for literal values

Functions & Methods

  • Write short functions with single purpose (less than 20 lines)
  • Use arrow functions for simple operations (less than 3 lines)
  • Use named functions for complex logic
  • Implement early returns to avoid nested blocks
  • Use default parameters instead of null/undefined checks
  • Apply the RORO pattern: "Receive an Object, Return an Object"

Data & Classes

  • Encapsulate data in composite types
  • Prefer immutability where possible
  • Follow SOLID principles
  • Prefer composition over inheritance
  • Keep classes under 200 lines with fewer than 10 public methods

Error Handling

  • Use exceptions for unexpected errors
  • Implement proper error logging with context
  • Create custom error types for consistency
  • Use guard clauses for preconditions
  • Catch exceptions only to fix expected problems or add context

Documentation

  • Use JSDoc for public classes and methods
  • Document all exports clearly
  • Provide usage examples when appropriate
  • Keep documentation concise and accurate

來源與署名

來源:Mindrally/skills位於typescript提交7682ca7

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架