React/TypeScript frontend development rules including type safety, component design, state management, and error handling. Use when implementing React components, TypeScript code, or frontend features.
67
58%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Optimize this skill with Tessl
npx tessl skill review --optimize ./skills/typescript-rules/SKILL.md✅ Aggressive Refactoring - Prevent technical debt and maintain health ❌ Unused "Just in Case" Code - Violates YAGNI principle (Kent Beck)
Absolute Rule: any type is completely prohibited. It disables type checking and becomes a source of runtime errors.
any Type Alternatives (Priority Order)
Type Guard Implementation Pattern
function isUser(value: unknown): value is User {
return typeof value === 'object' && value !== null && 'id' in value && 'name' in value
}Modern Type Features
const config = { apiUrl: '/api' } satisfies Config - Preserves inferenceconst ROUTES = { HOME: '/' } as const satisfies Routes - Immutable and type-safetype UserId = string & { __brand: 'UserId' } - Distinguish meaningtype EventName = \on${Capitalize<string>}`` - Express string patterns with typesType Safety in Frontend Implementation
unknown, validate with type guardsunknown, validateunknown, validateType Safety in Data Flow
unknown) → Type Guard → State (Type Guaranteed)Type Complexity Management
Component Design Criteria
State Management Patterns
useState for component-specific stateData Flow Principles
// ✅ Immutable state update
setUsers(prev => [...prev, newUser])
// ❌ Mutable state update
users.push(newUser)
setUsers(users)Function Design
// ✅ Object parameter
function createUser({ name, email, role }: CreateUserParams) {}Props Design (Props-driven Approach)
Environment Variables
process.env does not work in browsers// ✅ Build tool environment variables (public values only)
const config = {
apiUrl: import.meta.env.API_URL || 'http://localhost:3000',
appName: import.meta.env.APP_NAME || 'My App'
}
// ❌ Does not work in frontend
const apiUrl = process.env.API_URLSecurity (Client-side Constraints)
.env files in Git// ❌ Security risk: API key exposed in browser
const apiKey = import.meta.env.API_KEY
const response = await fetch(`https://api.example.com/data?key=${apiKey}`)
// ✅ Correct: Backend manages secrets, frontend accesses via proxy
const response = await fetch('/api/data') // Backend handles API key authenticationDependency 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
Basic Policy
Implementation Procedure: Understand Current State → Gradual Changes → Behavior Verification → Final Validation
Priority: Duplicate Code Removal > Large Function Division > Complex Conditional Branch Simplification > Type Safety Improvement
build script and keep under 500KB2e719be
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.