T19
Warning
Types
T19 — A value that may be null, shown as text
Spliced into text, null shows as null (and a missing value as undefined). Say what to show instead with ??.
What the compiler said
warning[T19]: `user.nickname` may be null, and in text it would show as `null` --> src/App.wf:5:26 | 5 | Text("Also known as {user.nickname}") | ^^^^^^^^^^^^^ = help: Say what to show instead: `{user.nickname ?? ""}` = docs: https://webfluent.monzeromer.dev/errors/T19
The fix
Broken
type Member { name: String, nickname: String? }
page P(path: "/", title: "T", description: "D") {
state user = Member(name: "Ada", nickname: null)
Heading("Hello").h1
Text("Also known as {user.nickname}")
}
Fixed
type Member { name: String, nickname: String? }
page P(path: "/", title: "T", description: "D") {
state user = Member(name: "Ada", nickname: null)
Heading("Hello").h1
Text("Also known as {user.nickname ?? "nothing yet"}")
}
Say what to show instead: {user.nickname ?? "nothing yet"}, or
show the line only when there is one: if let n = user.nickname { … }.
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
Warning.
lints may lower it:
"lints": { "T19": "off" }
// wf-allow(T19)