T32
Error
Types
T32 — A parameter written with no type
What another declaration or a caller sees is declared: an action's, an event's or a slot's parameter says its type, and so does a lambda's when nothing it is passed to says it.
What the compiler said
error[T32]: `title` of `add` says nothing of its type --> src/App.wf:3:5 | 3 | action add(title) { titles = titles.concat([title]) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Every call passes a `String`: write `title: String` = docs: https://webfluent.monzeromer.dev/errors/T32
Your editor offers this fix: Declare title: String. wf fix --code T32 applies it to every place it fits.
The fix
Broken
store Todos {
state titles: [String] = []
action add(title) { titles = titles.concat([title]) }
}
page P(path: "/", title: "Todos", description: "D") {
use Todos
Heading("Todos").h1
Button("Add") { on click { Todos.add("Milk") } }
for title in Todos.titles { Text(title) }
}
Fixed
store Todos {
state titles: [String] = []
action add(title: String) { titles = titles.concat([title]) }
}
page P(path: "/", title: "Todos", description: "D") {
use Todos
Heading("Todos").h1
Button("Add") { on click { Todos.add("Milk") } }
for title in Todos.titles { Text(title) }
}
Write the type. For an action's parameter, the editor's quick fix
and wf fix --code T32 write the type every call of it passes, when they
all pass 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.
A parameter is what a caller sees, so it says its type: an action's
(action add(title: String)), an event's (event pick(id: String)), a
slot's (slot row(item: Todo)). A lambda's parameters are worked out from
what it is passed to — rows.filter(r => r.live) — and are written only
when nothing says them: derived byName = (a: User, b: User) =>
a.name.localeCompare(b.name).
lints cannot lower it: it would ship a broken page.