T33
Error
Types
T33 — Data that is not what its type says
Data that comes from outside the program is held to the type that receives it, where it comes in: a data file when the project is built, a template's data before it renders, a test's data: seeds before it runs. A value that does not fit is named by its place — $[3].date is "March 5", not a Date — rather than shown wrong, or as nothing, on the page.
The fix
Correct the data at the place the message names, or change the type to what the data holds.
Why this rule exists
Error.
A template that says what it takes, and data that is not that:
type Line { name: String, price: Number }
page Invoice(path: "/", title: "Invoice", number: String, items: [Line]) {
Heading("Invoice #{number}").h1
for item in items { Text("{item.name}: {item.price}") }
}
$ echo '{"number": "7", "items": [{"name": "Widget"}]}' | wf render invoice.wf
error[T33]: the data is not what `Invoice` takes: $.items[0].price is missing
--> <data>:1:1
= help: `Invoice` takes `number`, `items`
Data that comes in from outside the program is held to the type that receives it, where it comes in, and refused with the place it goes wrong:
- A
datafile, when the project is built: `data posts: [Post] =
"posts.json" reads the file and holds it to [Post] —
posts.json is not what data posts says it is: $[3].date is "March
5", not a Date `.
- A template's data, before every render: a page that declares
parameters beside its route's — page Invoice(path: "/", number: String,
items: [Line]) — takes those, and data that does not fit is refused
($.items[1].price is missing) rather than drawn as an empty cell.
- A test's
data:, before the test runs: a seed is held to the state it
seeds, count is "two", not a Number.
A value kept with persist is held to its type when it is read back too,
and one that does not fit is dropped for the initial value rather than
reported: a reader's storage never stops a page from loading.
lints cannot lower it: it would ship a broken page.