feat: add typed WRN declarations
This commit is contained in:
+26
-8
@@ -151,17 +151,32 @@ layout = "public"
|
||||
|
||||
```
|
||||
props {
|
||||
start = 0 // default's TYPE drives coercion: start="5" arrives as number 5
|
||||
label = "Count" // string
|
||||
disabled = false // boolean
|
||||
title: string // required: no default
|
||||
start: number = 0 // start="5" arrives as number 5
|
||||
disabled: boolean = false
|
||||
items: Array<Item> = []
|
||||
}
|
||||
```
|
||||
|
||||
Type annotations use TypeScript syntax. Legacy declarations without an annotation still infer their
|
||||
runtime type from the default value.
|
||||
|
||||
### `types { }` — local TypeScript models
|
||||
|
||||
```ts
|
||||
types {
|
||||
interface Item { id: string; label: string }
|
||||
type Status = "idle" | "loading" | "ready"
|
||||
}
|
||||
```
|
||||
|
||||
These declarations can be referenced by props, state, and function signatures in the same file.
|
||||
|
||||
### `state` — ⚠️ one per line
|
||||
|
||||
```
|
||||
state count = start // may reference a prop or earlier state
|
||||
state total = 0
|
||||
state count: number = start // may reference a prop or earlier state
|
||||
state status: Status = "idle"
|
||||
```
|
||||
|
||||
State seeds the reactive scope. On pages, seeds are also evaluated at compile time for SSR baking.
|
||||
@@ -198,15 +213,18 @@ style {
|
||||
Multiple `style` blocks accumulate. Use theme tokens (`var(--wire-*)`) so styles restyle on theme
|
||||
change.
|
||||
|
||||
### `functions { }` — shared **server‑only** helpers
|
||||
### `functions { }` — typed helpers
|
||||
|
||||
```
|
||||
functions {
|
||||
function slug(s) { return s.toLowerCase().replace(/\s+/g, "-"); }
|
||||
function slug(value: string): string {
|
||||
return value.toLowerCase().replace(/\s+/g, "-");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Available to `api`, `ssr`/`client`, and `realtime` bodies.
|
||||
Component functions are available to events, lifecycle hooks, and watchers in the browser as well as
|
||||
server rendering. Page helpers are available to `api`, `ssr`/`client`, and `realtime` bodies.
|
||||
|
||||
### `api <METHOD> <path> { }` — colocated API route
|
||||
|
||||
|
||||
Reference in New Issue
Block a user