name: typescript-frontend description: Implement robust, type-safe frontend code with TypeScript best practices, advanced types, and integration patterns for React, Vue, and vanilla JavaScript applications.
TypeScript Frontend Development Skill
๐ฏ Purpose
This skill provides comprehensive guidance for implementing robust, type-safe frontend code using TypeScript best practices, advanced type system features, and integration patterns. It ensures high-quality, maintainable, and error-resistant frontend applications.
๐ When to Use
- When adding TypeScript to existing JavaScript projects
- When creating new TypeScript-based frontend applications
- When implementing complex type systems and generics
- When integrating TypeScript with React, Vue, or other frameworks
- When setting up TypeScript configuration and tooling
- When optimizing TypeScript for performance and bundle size
- When creating type definitions for third-party libraries
๐ง Core Capabilities
- Type System Mastery: Advanced types, generics, conditional types, mapped types
- Framework Integration: React + TypeScript, Vue + TypeScript patterns
- Configuration: tsconfig.json optimization, compiler options, build setup
- Type Safety: Runtime validation, type guards, discriminated unions
- Performance: Tree-shaking, dead code elimination, bundle optimization
- Testing: Type-aware testing strategies and mocking
- Migration: JavaScript to TypeScript migration strategies
- Tooling: ESLint, Prettier, VS Code integration
๐ Development Workflow
- Project Assessment: Evaluate current codebase and TypeScript readiness
- Configuration Setup: Configure tsconfig.json with appropriate compiler options
- Incremental Migration: Add types incrementally without breaking changes
- Type Design: Create meaningful, reusable type definitions
- Integration Patterns: Implement framework-specific TypeScript patterns
- Validation: Add runtime type checking where necessary
- Testing: Write type-aware tests and validate type safety
- Documentation: Document type interfaces and usage patterns
โ ๏ธ Best Practices & Guidelines
Type Design Principles
- Meaningful Names: Use descriptive, domain-specific type names
- Composition over Inheritance: Favor intersection and union types
- Discriminated Unions: Use for state machines and variant types
- Brand Types: Create nominal types to prevent accidental assignment
- Utility Types: Leverage built-in and custom utility types
- Avoid any: Never use
any- preferunknownwith type guards
Framework Integration
- React: Component props, hooks return types, context types
- Vue: Component props, emits, slots, composable return types
- Vanilla JS: Module augmentation, global types, declaration files
- Libraries: Type definitions for third-party dependencies
Configuration Optimization
- Strict Mode: Enable strict type checking options
- Module Resolution: Configure proper module resolution strategy
- Target Compatibility: Set appropriate ECMAScript target
- Source Maps: Enable for debugging and error tracking
- Incremental Builds: Optimize compilation speed
Performance Considerations
- Tree-shaking: Ensure types don't bloat production bundles
- Dead Code Elimination: Remove unused type imports
- Bundle Analysis: Monitor type-related bundle impact
- Compilation Speed: Optimize tsconfig for development vs production
๐ ๏ธ Advanced Type Patterns
Utility Types
- Partial
: Make all properties optional - Required
: Make all properties required - Readonly
: Make all properties readonly - Pick<T, K>: Select specific properties
- Omit<T, K>: Exclude specific properties
- Record<K, T>: Create object with specific key-value types
- Exclude<T, U>: Exclude types from union
- Extract<T, U>: Extract types from union
Custom Utility Types
- DeepPartial
: Recursively make all properties optional - DeepRequired
: Recursively make all properties required - Nullable
: Make type nullable (T | null) - Maybe
: Make type optional (T | undefined) - NonEmptyArray
: Array with at least one element - Tuple<T, N>: Fixed-length array of specific type
Conditional Types
- Distributive Conditional Types: Apply conditionals to union members
- Infer Keyword: Extract types from complex structures
- Template Literal Types: Create string manipulation types
- Key Remapping: Transform object keys in mapped types
๐ก Integration Patterns
React + TypeScript
- Component Props: Interface vs type, defaultProps handling
- Hooks: Custom hook return types, generic hooks
- Context: Typed context values and providers
- Event Handlers: Proper event typing and handler signatures
- Refs: ForwardRef, MutableRefObject, RefObject
Vue + TypeScript
- Component Props: defineProps with runtime + type safety
- Emits: defineEmits with proper event typing
- Slots: Typed slot content and fallbacks
- Composables: Return type inference and generic composables
- Stores: Pinia store typing and actions
API Integration
- Fetch Responses: Typed API response structures
- Error Handling: Discriminated union for success/error states
- Validation: Runtime validation with Zod, Yup, or custom validators
- Serialization: Type-safe JSON serialization/deserialization
๐ Examples
- "Create a type-safe API client with TypeScript generics and error handling"
- "Implement a discriminated union for form state management"
- "Add TypeScript to an existing React component with proper prop typing"
- "Create custom utility types for common frontend patterns"
- "Set up TypeScript configuration for a Vue 3 + Vite project"
- "Implement runtime type validation with Zod for API responses"
๐ฏ Success Criteria
- Code is fully type-safe with no implicit any errors
- Types are meaningful and improve code readability
- Build times are optimized for development workflow
- Bundle size is not negatively impacted by type annotations
- Migration from JavaScript is smooth and incremental
- Error messages are clear and actionable
- Team adoption is successful with proper documentation
๐ Integration with Other Skills
- react-development: Provide TypeScript integration for React components
- vue-development: Provide TypeScript integration for Vue components
- frontend-design: Ensure type safety in design system components
- webapp-testing: Create type-aware test utilities and mocks
- playwright-skill: Type-safe Playwright test configurations
๐ Quality Metrics
- Type Coverage: 100% type coverage with no implicit any
- Build Performance: Compilation time under 10 seconds for medium projects
- Bundle Impact: Zero runtime impact from type annotations
- Error Reduction: 50%+ reduction in runtime type-related errors
- Developer Experience: Clear, actionable error messages and autocomplete