一键导入
frontend-typescript-rules
React/TypeScript frontend development rules including type safety, component design, state management, and error handling.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
React/TypeScript frontend development rules including type safety, component design, state management, and error handling.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Universal coding standards for implementation, code quality, testing, and refactoring. Covers anti-patterns, type safety, debugging, Red-Green-Refactor development, test design, code duplication (Rule of Three), decision frameworks, and impact analysis. Use when implementing features, reviewing code quality, fixing bugs, or refactoring.
Enforce unidirectional flow: state → UI (selectors) → actions → updates. Prevent direct store access from components, use granular selectors, implement reselect for complex filtering/sorting/aggregation. Use when designing component data flow or optimizing re-renders.
Implement error handling: try-catch at boundaries, typed errors with instanceof checks, error state in store, error boundaries for components, exponential backoff retry with jitter, Sentry monitoring in production, user-friendly error messages. Use when implementing API calls, form submissions, or component error boundaries.
Implement state management: Zustand slices pattern, manual immutable updates with spread operators, middleware stack (devtools, subscribeWithSelector), Immer decision matrix (4+ spreads → use Immer), transient updates for 10+ updates/sec. Use when implementing stores or managing complex state.
Frontend technical design rules including environment variables, architecture design, data flow, Nx workspace conventions, and build/testing commands.
Enforce type safety: Zod runtime validation at boundaries, type guards for discriminated unions, avoid any/unknown, validate before asserting. Optimize Zod with .pick()/.partial() on hot paths. Use when implementing API integrations, form handling, or state management with strict typing.
| name | frontend/typescript-rules |
| description | React/TypeScript frontend development rules including type safety, component design, state management, and error handling. |
In addition to universal anti-patterns in coding-standards skill, watch for these Frontend-specific issues:
Type Safety in Data Flow
unknown) -> Type Guard -> State (Type Guaranteed)Frontend-Specific Type Scenarios:
unknown, validate with type guardsunknown, validateunknown, validateType Complexity Management (Frontend)
Component Design Criteria
Function Design
// Object parameter
function createUser({ name, email, role }: CreateUserParams) {}
Props Design (Props-driven Approach)
Environment Variables
process.env does not work in browsersDependency Injection
Asynchronous Processing
async/awaittry-catch or Error BoundaryPromise<Result>)Format Rules
PascalCase, variables/functions in camelCasesrc/)Clean Code Principles
console.log()Absolute Rule: Error suppression prohibited. All errors must have log output and appropriate handling.
Fail-Fast Principle: Fail quickly on errors to prevent continued processing in invalid states
// Prohibited: Unconditional fallback
catch (error) {
return defaultValue // Hides error
}
// Required: Explicit failure
catch (error) {
logger.error('Processing failed', error)
throw error // Handle with Error Boundary or higher layer
}
Result Type Pattern: Express errors with types for explicit handling
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };
// Example: Express error possibility with types
function parseUser(data: unknown): Result<User, ValidationError> {
if (!isValid(data)) return { ok: false, error: new ValidationError() };
return { ok: true, value: data as User };
}
Custom Error Classes
export class AppError extends Error {
constructor(message: string, public readonly code: string, public readonly statusCode = 500) {
super(message);
this.name = this.constructor.name;
}
}
// Purpose-specific: ValidationError(400), ApiError(502), NotFoundError(404)
Layer-Specific Error Handling (React)
Structured Logging and Sensitive Information Protection Never include sensitive information (password, token, apiKey, secret, creditCard) in logs
Asynchronous Error Handling in React
build script and keep under 500KB