T25

Error

Types

T25 — A state whose first value does not say what it holds

A state or persist is inferred only from a value that says everything — a number, a string, a case, a record, a list or map with items. An empty list, an empty map, null or open JSON says nothing, so the declaration says what it holds: state items: [Todo] = [].

What the compiler said

error[T25]: `state items`'s first value does not say what it holds --> src/App.wf:4:5 | 4 | state items = [] | ^^^^^^^^^^^^^^^^ = help: Write what it holds: `state items: [Todo] = …` = docs: https://webfluent.monzeromer.dev/errors/T25

Your editor offers this fix: Declare items: [Todo]. wf fix --code T25 applies it to every place it fits.

The fix

Broken

wf

type Todo { id: String, title: String } page P(path: "/", title: "Todos", description: "D") { state items = [] Heading("Todos").h1 Button("Add") { on click { items = items.concat([Todo(id: "1", title: "Milk")]) } } for todo in items by todo.id { Text(todo.title) } }

Fixed

wf

type Todo { id: String, title: String } page P(path: "/", title: "Todos", description: "D") { state items: [Todo] = [] Heading("Todos").h1 Button("Add") { on click { items = items.concat([Todo(id: "1", title: "Milk")]) } } for todo in items by todo.id { Text(todo.title) } }

Write the type after the name. The editor's quick fix and wf fix --code T25 write the type the body later assigns — items = items.concat([Todo(…)]) gives [Todo] — when the body assigns one.

Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).

Why this rule exists

Error.

What another declaration, another file or a caller sees is declared; what only the body sees is inferred. A state or persist is inferred from its first value when that value says everything — 0, "x", .calm, Todo(…), [1, 2], { name: "", age: 0 }. An empty list, an empty map, null, or JSON that could be anything says nothing of what will be kept there, so the declaration says it: state items: [Todo] = [], state picked: User? = null, persist prefs: [String: Bool] = {}.

lints cannot lower it: it would ship a broken page.