T31
Error
Types
T31 — A script's function the language cannot type
A project script's JSDoc is its signature. A function called from .wf with none, or with a type the language cannot say — a union, an Array that does not say what it holds — has no signature to check a call or its result against.
What the compiler said
error[T31]: `tiltBy` has no JSDoc, so nothing says what it takes or gives back --> src/App.wf:3:24 | 3 | Card(mount: (n) => tiltBy(n, 15)) { Text("Lean on me.") } | ^^^^^^ = help: Say it above the function, at src/tilt.js:2: `/** @param {number} max … @returns {string} */`; the fix writes one from this call, `@returns {*}` for you to narrow = docs: https://webfluent.monzeromer.dev/errors/T31
The fix
Broken
page P(path: "/", title: "Tilt", description: "D") {
Heading("Tilt").h1
Card(mount: (n) => tiltBy(n, 15)) { Text("Lean on me.") }
}
Fixed
page P(path: "/", title: "Tilt", description: "D") {
Heading("Tilt").h1
Card(mount: (n) => tiltBy(n, 15)) { Text("Lean on me.") }
}
Write the JSDoc. The editor's quick fix and wf fix --code T31
write a block above the function from the call — each parameter's type as
the call passes it, and @returns {*} for you to narrow.
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.
// src/tilt.js
function tiltBy(node, max) {
node.style.transform = `rotate(${max}deg)`;
}
// src/tilt.js
/**
* @param {HTMLElement} node
* @param {number} max degrees
*/
function tiltBy(node, max) {
node.style.transform = `rotate(${max}deg)`;
}
A script under src/ stays plain JavaScript, and its JSDoc is its
signature: what each parameter is, and what comes back. A function called
from .wf with no JSDoc says neither, so nothing could check the call or
what is done with its result. A JSDoc type the language has no word for
says nothing either: a union ({string|number} — use two functions, or
{*} for any JSON) or an {Array} that does not say what it holds
({string[]}).
What the JSDoc says is held at both ends: each call is checked against the
@params, and what the function returns is checked against its @returns
as it returns, in every build — a mismatch throws a DecodeError naming
the function. A function with JSDoc and no @returns gives nothing back.
lints cannot lower it: it would ship a broken page.