Requirements
Basic Setup
tsconfig.json
Configure your TypeScript compiler for Theme UI:The JSX Automatic Runtime (
react-jsx) is highly encouraged to minimize friction and avoid type errors.File-level JSX Import Source
Override the default JSX import source per file:Type Definitions
SxProp Type
TheSxProp interface adds the sx prop to components:
ThemeUIStyleObject
The main type for style objects:Theme Type
The complete theme interface:Extending Theme Types
Customize the theme type to add autocomplete for your specific theme structure.Method 1: Module Augmentation
Extend the global theme type:Method 2: Strict Theme Type
Create a strictly typed theme from scratch:Component Types
Adding sx to Custom Components
Box Component Props
Themed Component Type
Type definition forThemed components from @theme-ui/mdx:
Responsive Style Values
TypeScript supports responsive arrays:Theme-aware Function Types
Style values can be functions that receive the theme:Utility Types
Scale Types
Nested Scales with __default
Common Type Errors
Error: Property ‘sx’ does not exist
Ensure@jsxImportSource theme-ui is at the top of your file:
Error: Type ‘string’ is not assignable to type ‘never’
This happens when TypeScript can’t infer theme types. Add explicit types:Error: Index signature is missing
When accessing theme values dynamically:Advanced Patterns
Discriminated Union for Variants
Generic Themed Component
Const Assertion for Strict Typing
Migration from JavaScript
Converting a JavaScript theme to TypeScript:Resources
TypeScript Handbook
Official TypeScript documentation
Emotion TypeScript
TypeScript guide for Emotion
Theme UI GitHub
Source code and type definitions
Migration Guide
Upgrading to latest version
