|
| 1 | +export const metadata = { |
| 2 | + title: 'Type Inference System', |
| 3 | + alternates: { |
| 4 | + canonical: '/docs/core-concepts/type-inference-system', |
| 5 | + }, |
| 6 | +} |
| 7 | + |
| 8 | +# Type Inference System |
| 9 | + |
| 10 | +Devup UI automatically infers TypeScript types for CSS properties, ensuring type safety and a smooth developer experience — no manual definitions required. |
| 11 | +Unlike traditional CSS-in-JS libraries, Devup UI **derives types directly from CSS standards**. |
| 12 | + |
| 13 | +## How It Works |
| 14 | + |
| 15 | +The type inference process consists of four main steps: |
| 16 | + |
| 17 | +1. **Parsing** – analyzes JSX/TSX code |
| 18 | +2. **Property Lookup** – checks against the CSS property map |
| 19 | +3. **Type Generation** – produces corresponding TypeScript types |
| 20 | +4. **Validation** – enforces compile-time correctness |
| 21 | + |
| 22 | +### 1. CSS Property Mapping |
| 23 | + |
| 24 | +All CSS properties are defined in a Rust-based mapping table. |
| 25 | + |
| 26 | +```rust |
| 27 | +pub(super) static GLOBAL_STYLE_PROPERTY: phf::Map<&str, &[&str]> = phf_map! { |
| 28 | + "bg" => &["background"], |
| 29 | + "bgColor" => &["background-color"], |
| 30 | + "m" => &["margin"], |
| 31 | + "w" => &["width"], |
| 32 | + "h" => &["height"], |
| 33 | + // ... |
| 34 | +}; |
| 35 | + |
| 36 | +``` |
| 37 | + |
| 38 | +### 2. Type Generation |
| 39 | + |
| 40 | +TypeScript types are automatically derived from CSS property names and value patterns. |
| 41 | + |
| 42 | +It supports various value types — such as lengths, colors, and percentages — and |
| 43 | + |
| 44 | +ensures **type-safe responsive arrays** for breakpoint-based styles. |
| 45 | + |
| 46 | +```tsx |
| 47 | +<Box w={[100, 200, 300]} /> |
| 48 | +``` |
| 49 | + |
| 50 | +### 3. Special Property Handling |
| 51 | + |
| 52 | +Certain properties are excluded from inference, such as React-specific or HTML attributes. |
| 53 | + |
| 54 | +```rust |
| 55 | +static SPECIAL_PROPERTIES: phf::Set<&str> = phf_set! { |
| 56 | + "children", "ref", "key", "className", "id", "style", |
| 57 | +}; |
| 58 | + |
| 59 | +``` |
| 60 | + |
| 61 | +## Advantages |
| 62 | + |
| 63 | +Devup UI’s type inference system provides several key benefits: |
| 64 | + |
| 65 | +- **Automatic updates** – New CSS properties are supported immediately when standards evolve, without requiring library updates. |
| 66 | +- **Type safety** – All properties and values are strictly typed, preventing invalid or misspelled declarations at compile time. |
| 67 | +- **Extensibility** – Experimental or custom CSS features can be easily extended within the system. |
| 68 | + |
| 69 | +This type inference system is automatic, reliable, and future-ready, allowing developers to focus on design and logic rather than manual type management. |
0 commit comments