Declare and AI-generated UI — what can the compiler check?
AI can build buttons and screens quickly, but you still need to know which elements update when state changes. David Temkin’s Declare is a domain-specific language for UI structure, state, and properties that depend on that state. You describe the screen in a .declare file and use TypeScript for event handling and calculations. The compiler checks the relationships defined in the UI, and a separate verifier drives the running app and checks its state and appearance. Declare repository
What updates when you click the button?
This counter is based on the example in the Declare language guide. App is the root of the UI, and count: number = 0 declares numeric state starting at zero. Square brackets [...] group an element’s properties, handlers, and children. The View lays out the button and text vertically. In onClick() { ... }, the braces contain TypeScript that runs on a click. In text = { ... }, they contain an expression that reads app.count to build the displayed message. Counter in the language guide
App [
width = 400, height = 140,
fill = darkslategray, textColor = whitesmoke,
count: number = 0,
col: View [
x = center, y = center,
layout: SimpleLayout [ axis = y, spacing = 14, align = center ],
Button [
label = "Add one",
onClick() { app.count = app.count + 1 }
],
Text [
text = { `Click count: ${app.count}` }
]
]
]
The first click takes count from zero to one. The runtime recalculates Text.text because it depends on that value, so the expected message is “Click count: 1”. The expression in text = { ... } is a constraint maintained by the runtime. A button’s enabled state or a hint that reads the same value will also update when it changes. One path uses dependencies wired by the compiler ahead of time, and another tracks the values the expression actually reads as it runs. Compiler source, Reactive runtime source
The official calendar uses the same model. Its day, week, month, and year views share a surface that pans and zooms continuously. The counter uses state to change a message, while the calendar uses drag and zoom state to change the position and visible range of the view. Calendar demo, Calendar source
What should you check after compilation?
declare-verify runs the cheapest checks first and stops at the first failure. It checks syntax and types before starting the app. When you provide scripts, it can also check the effect of real inputs and compare screen states. declare-verify documentation
| Stage | What it checks |
|---|---|
| 1–3 Structure, resolution, and analysis | Syntax errors, unresolved names, and type errors, among other issues |
| 4 Startup | Whether the initial screen opens, visible text overflows or is clipped, or touch targets are too small in touch mode |
| 5 Behavior | Whether clicks or drags in the script produce the expected state |
| 6 Visual comparison | Whether named screen states match baseline images |
A successful startup does not tell you whether dragging an event to another day also changes its saved date. Use a behavior script to check that requirement. Have the script open any screens that are absent at startup. Use the live Inspector to trace the expression and inputs behind a value, then record the issue in a verification script so you can catch a recurrence. Official Declare site
Where is Declare worth trying?
Start with a small settings screen or an interactive prototype where several UI properties depend on the same state. Pick one panel with a state transition, keyboard interaction, and a narrow-screen layout. See if you can check all three with the same script after an AI edit. Before adopting Declare in an app, check focus and screen reader behavior on the renderer you intend to use. The project supports DOM and Canvas rendering and describes WebGPU and native macOS as experimental. The repository uses the MIT license. Declare repository, Accessibility guide, MIT license
The official site shows how Declare and React were used to implement the same ticket-buying brief. The project published a single comparison, so read its figures as results for that task. When evaluating Declare for a team, ask which requirements you could express as checks and which behaviors you could recheck after an AI edit. Official Declare site
The review compared the language guide, compiler and runtime source, calendar example, and verifier documentation at commit 91a0be6. It did not include running the example or measuring performance or accessibility.
Related reading — Improving AI-generated Java code
Discussion