{"record":{"id":"0e78ee6e8096e8c5","repo":"slint-ui/slint","slug":"expect-boolean-got-vt","errorCode":null,"errorMessage":"expect Boolean, got: {vt:?}","messagePattern":"expect Boolean, got: (.+?)","errorType":"validation","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"api/node/rust/interpreter/value.rs","lineNumber":55,"sourceCode":"    }\n}\n\n/// Safely extract a String from an Unknown, failing if the type is wrong.\nfn expect_string(unknown: Unknown<'_>) -> Result<String> {\n    match unknown.get_type()? {\n        ValueType::String => Ok(unknown.coerce_to_string()?.into_utf8()?.as_str()?.to_owned()),\n        vt => Err(napi::Error::new(\n            napi::Status::StringExpected,\n            format!(\"expect String, got: {vt:?}\"),\n        )),\n    }\n}\n\n/// Safely extract a bool from an Unknown, failing if the type is wrong.\nfn expect_bool(unknown: Unknown<'_>) -> Result<bool> {\n    match unknown.get_type()? {\n        ValueType::Boolean => Ok(unknown.coerce_to_bool()?),\n        vt => Err(napi::Error::new(\n            napi::Status::BooleanExpected,\n            format!(\"expect Boolean, got: {vt:?}\"),\n        )),\n    }\n}\n\n#[napi(js_name = \"ValueType\")]\npub enum JsValueType {\n    Void,\n    Number,\n    String,\n    Bool,\n    Model,\n    Struct,\n    Brush,\n    Image,\n    Keys,\n}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/node/rust/interpreter/value.rs#L37-L73","documentation":"expect_bool in the Node.js interpreter binding converts a Slint Value to a JS boolean. When the Value's type is not Boolean, it throws a napi Error with status BooleanExpected including the actual ValueType. This prevents silently truthy-coercing non-boolean Slint values into JS.","triggerScenarios":"Converting a Slint Value that is a number, string, brush, struct, model, or image through a boolean-expecting path; reading an `int` or `float` .slint property as if it were `bool`.","commonSituations":"JS code assuming 0/1 numbers are booleans after a .slint refactor; property type changed from bool to something else; wrong struct field picked from a Slint struct.","solutions":["Confirm the .slint property is declared `bool` before converting via expect_bool.","Fix the .slint declaration to `bool` if a boolean was intended.","In JS, branch on the value type and use the numeric/string converters for non-boolean values."],"exampleFix":"// before\nconst b = expect_bool(value);\n// after\nconst b = typeof value === 'boolean' ? value : Boolean(coerceSlintValue(value));","handlingStrategy":"type-guard","validationCode":"function isSlintBool(v) {\n  return typeof v === 'boolean' || slintValueType(v) === 'boolean';\n}","typeGuard":"const isBoolValue = (v) => slintValueType(v) === 'Boolean';","tryCatchPattern":"try {\n  const b = toValue(value);\n} catch (e) {\n  if (e.code === napi.Status.BooleanExpected) {\n    // handle non-boolean value\n  } else throw e;\n}","preventionTips":["Do not rely on 0/1 numbers standing in for booleans at the boundary.","Keep .slint `bool` properties unchanged when refactoring types.","Assert property types in tests that read them from JS."],"tags":["nodejs","type-mismatch","interpreter","napi"],"backgroundTag":"type-mismatch","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}