slint-ui/slint · error · napi::Error
expect Boolean, got
Error message
expect Boolean, got: {vt:?} What it means
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.
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.
Example fix
// before const b = expect_bool(value); // after const b = typeof value === 'boolean' ? value : Boolean(coerceSlintValue(value));
Defensive patterns
Strategy: type-guard
Validate before calling
function isSlintBool(v) {
return typeof v === 'boolean' || slintValueType(v) === 'boolean';
} Type guard
const isBoolValue = (v) => slintValueType(v) === 'Boolean';
Try / catch
try {
const b = toValue(value);
} catch (e) {
if (e.code === napi.Status.BooleanExpected) {
// handle non-boolean value
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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`.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- expect Number, got
- expect String, got
- Failed to create weak reference
- First argument not an array
- Invalid property type for
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/0e78ee6e8096e8c5.
Report an issue: GitHub.
Appendix: source
Thrown at api/node/rust/interpreter/value.rs:55
}
}
/// Safely extract a String from an Unknown, failing if the type is wrong.
fn expect_string(unknown: Unknown<'_>) -> Result<String> {
match unknown.get_type()? {
ValueType::String => Ok(unknown.coerce_to_string()?.into_utf8()?.as_str()?.to_owned()),
vt => Err(napi::Error::new(
napi::Status::StringExpected,
format!("expect String, got: {vt:?}"),
)),
}
}
/// Safely extract a bool from an Unknown, failing if the type is wrong.
fn expect_bool(unknown: Unknown<'_>) -> Result<bool> {
match unknown.get_type()? {
ValueType::Boolean => Ok(unknown.coerce_to_bool()?),
vt => Err(napi::Error::new(
napi::Status::BooleanExpected,
format!("expect Boolean, got: {vt:?}"),
)),
}
}
#[napi(js_name = "ValueType")]
pub enum JsValueType {
Void,
Number,
String,
Bool,
Model,
Struct,
Brush,
Image,
Keys,
}View on GitHub (pinned to bb937076de)