TypeScript
Reshaped is built with TypeScript and provides comprehensive type definitions for all components, hooks, and utilities. The library leverages advanced TypeScript features to provide excellent developer experience and type safety.Type Definitions
All Reshaped exports are fully typed:Component Props
Access component prop types for your own components:Generic Components
Some components support generic types for enhanced type safety.View Component with Custom Elements
attributes prop is typed based on the as prop:
Button with Custom Elements
Responsive Types
TheResponsive<T> type allows single values or viewport-specific values:
Creating Responsive Props
Viewport Types
Theme Types
Theme and color mode types are strongly typed:Form Types
Form components provide type-safe change handlers:Generic ChangeHandler
Style Types
Style-related types are exported for custom components:Ref Types
Components that expose refs are properly typed:Attributes Type
Theattributes prop is typed using the Attributes<T> utility type:
Type Inference
Reshaped leverages TypeScript’s type inference to reduce boilerplate:Utility Types
Responsive Utilities
Mixin Types
Style mixins for creating custom styled components:Type Guards
Create type guards for runtime checks:Extending Component Props
Create wrapper components with additional props:Best Practices
- Import types separately - Use
import typefor better tree-shaking - Leverage type inference - Let TypeScript infer types when possible
- Use generic components - Type the
asprop for better attribute typing - Extend, don’t override - Extend component props instead of redefining
- Create type guards - Use type guards for runtime responsive value checks
- Use utility types - Leverage built-in utility types like
Responsive<T> - Type your handlers - Always type event handlers and change handlers
Common Patterns
Typed Custom Hook
Typed Form State
Related
- Theming - Type-safe theme and color mode APIs
- Responsive Design - Responsive prop types
- Styling - Style prop types and mixins