{"filename":"typescript.mdc","content":"---\ndescription: \"TypeScript coding standards and best practices for modern web development\"\nglobs: **/*.ts, **/*.tsx, **/*.d.ts\nalwaysApply: false\n---\n# TypeScript Best Practices\n\n## Type System\n- Prefer interfaces over types for object definitions\n- Use type for unions, intersections, and mapped types\n- Avoid using `any`, prefer `unknown` for unknown types\n- Use strict TypeScript configuration\n- Leverage TypeScript's built-in utility types\n- Use generics for reusable type patterns\n\n## Naming Conventions\n- Use PascalCase for type names and interfaces\n- Use camelCase for variables and functions\n- Use UPPER_CASE for constants\n- Use descriptive names with auxiliary verbs (e.g., isLoading, hasError)\n- Prefix interfaces for React props with 'Props' (e.g., ButtonProps)\n\n## Code Organization\n- Keep type definitions close to where they're used\n- Export types and interfaces from dedicated type files when shared\n- Use barrel exports (index.ts) for organizing exports\n- Place shared types in a `types` directory\n- Co-locate component props with their components\n\n## Functions\n- Use explicit return types for public functions\n- Use arrow functions for callbacks and methods\n- Implement proper error handling with custom error types\n- Use function overloads for complex type scenarios\n- Prefer async/await over Promises\n\n## Best Practices\n- Enable strict mode in tsconfig.json\n- Use readonly for immutable properties\n- Leverage discriminated unions for type safety\n- Use type guards for runtime type checking\n- Implement proper null checking\n- Avoid type assertions unless necessary\n\n## Error Handling\n- Create custom error types for domain-specific errors\n- Use Result types for operations that can fail\n- Implement proper error boundaries\n- Use try-catch blocks with typed catch clauses\n- Handle Promise rejections properly\n\n## Patterns\n- Use the Builder pattern for complex object creation\n- Implement the Repository pattern for data access\n- Use the Factory pattern for object creation\n- Leverage dependency injection\n- Use the Module pattern for encapsulation\n"}