{"record":{"id":"e8a9617e875fde21","repo":"slint-ui/slint","slug":"expect-string-got-vt","errorCode":null,"errorMessage":"expect String, got: {vt:?}","messagePattern":"expect String, got: (.+?)","errorType":"validation","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"api/node/rust/interpreter/value.rs","lineNumber":44,"sourceCode":"    }\n}\n\n/// Safely extract a f64 from an Unknown, failing if the type is wrong.\nfn expect_number(unknown: Unknown<'_>) -> Result<f64> {\n    match unknown.get_type()? {\n        ValueType::Number => unknown.coerce_to_number()?.get_double(),\n        vt => Err(napi::Error::new(\n            napi::Status::NumberExpected,\n            format!(\"expect Number, got: {vt:?}\"),\n        )),\n    }\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\")]","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/node/rust/interpreter/value.rs#L26-L62","documentation":"expect_string in the Node.js interpreter binding extracts a JS string from a Slint Value. If the Value's type is not String, it throws a napi Error with status StringExpected and the actual ValueType in the message. It exists to fail fast rather than coerce unexpected types across the FFI boundary.","triggerScenarios":"Calling to_value on a Slint Value holding a number, bool, brush, struct, model, or image when a string is expected; reading a numeric .slint property through a string-expecting code path.","commonSituations":"A .slint property changed from string to another type while JS still treats it as text; locale/translation values stored as non-string types; passing model data of the wrong element type to JS.","solutions":["Verify the Slint value is actually a string (check the .slint property type) before converting.","Correct the .slint declaration to `string` if the value should be textual.","Add a type check in JS and route non-string values through the appropriate converter (expect_number/expect_bool)."],"exampleFix":"// before\nconst s = expect_string(value);\n// after\nconst s = typeof value === 'string' ? value : String(coerceSlintValue(value));","handlingStrategy":"type-guard","validationCode":"function isSlintString(v) {\n  return typeof v === 'string' || slintValueType(v) === 'string';\n}","typeGuard":"const isStringValue = (v) => slintValueType(v) === 'String';","tryCatchPattern":"try {\n  const s = toValue(value);\n} catch (e) {\n  if (e.code === napi.Status.StringExpected) {\n    // handle non-string value\n  } else throw e;\n}","preventionTips":["Declare text-bearing .slint properties as `string`.","Validate struct field types when passing Slint structs to JS.","Run interpreter binding tests after any .slint type change."],"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"}