T24
Error
Types
T24 — Map written as a type
7.0 took Map out of the language: it said nothing of its keys or what they hold, so a misspelt field read as nothing. Write a type with its fields, a dictionary [String: T], or Json for JSON whose shape is open.
What the compiler said
error[T24]: `prices` is written `Map`, which 7.0 took out of the language: it says nothing of the keys or what they hold --> src/App.wf:2:5 | 2 | state prices: Map = { tea: 3, coffee: 4 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Write a `type` with its fields, a dictionary `[String: T]`, or `Json` for JSON whose shape is open = docs: https://webfluent.monzeromer.dev/errors/T24
Your editor offers this fix: Write Json. wf fix --code T24 applies it to every place it fits.
The fix
Broken
page P(path: "/", title: "Prices", description: "D") {
state prices: Map = { tea: 3, coffee: 4 }
Heading("Prices").h1
Text("Tea is {prices.tea ?? 0}")
}
Fixed
page P(path: "/", title: "Prices", description: "D") {
state prices: [String: Number] = { tea: 3, coffee: 4 }
Heading("Prices").h1
Text("Tea is {prices.tea ?? 0}")
}
write one of them. The editor's quick fix, wf fix --code T24 and
wf migrate write Json; a record or a dictionary is better where you know
what it holds.
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 Map held anything under any key, so prices.tae read as nothing and the
page showed it. 7.0 says what a map is:
- a record, when its keys are known: `type Price { tea: Number, coffee:
Number } — a field it lacks is T05`;
- a dictionary, when its keys are not known but what they hold is:
[String: Number] — reading a key gives a Number?;
Json, when it is JSON whose shape is open, matched or decoded where it
is read.
lints cannot lower it: it would ship a broken page.