slint-ui/slint · error

Invalid type in public properties

Error message

Invalid type in public properties

What it means

In `cpp_live_preview.rs`, the live-preview public API generator maps each public property's Slint type to a C++ type via `cpp_type()`; a None result panics. This is the live-preview variant of the public-property type check: every type exposed on the generated live-preview facade must have a C++ representation and a value-conversion function.

Solutions

  1. Add the missing mapping in `Type::cpp_type()` (and `convert_from_value_fn` for the live preview)
  2. Change the property type in the .slint source to a C++-supported type or make it non-public
  3. Turn the expect into a proper diagnostic that names the property and type

Example fix

// before
let cpp_property_type = p.ty.cpp_type().expect("Invalid type in public properties");
// after
let cpp_property_type = p.ty.cpp_type().unwrap_or_else(||
    panic!("public property '{prop_name}' has C++-unsupported type {:?}", p.ty));
Defensive patterns

Strategy: validation

Validate before calling

fn check_live_preview_property(name: &str, ty: &Type) {
    assert!(ty.cpp_type().is_some(), "'{name}': type {ty:?} unsupported in live-preview public API");
}

Type guard

fn cpp_type_of(ty: &Type) -> Option<String> {
    ty.cpp_type().map(|t| t.to_string())
}

Prevention

When it happens

Trigger: `generate_public_api_for_properties` (called from `generate_public_component` or `generate_global`) encounters a public property whose type lacks a `cpp_type()` mapping, or whose `convert_from_value_fn` counterpart is also missing for the live-preview value path.

Common situations: Adding a new Slint builtin type without updating the C++/live-preview mappings; exposing internal-only types (layout constraints, native structs) as public properties; generated code from a newer compiler consumed by an older generator.

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


AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16). Data as JSON: /api/errors/7a6a30cd92299ab5. Report an issue: GitHub.

Appendix: source

Thrown at internal/compiler/generator/cpp_live_preview.rs:379

            )];
            declarations.push((
                Access::Public,
                Declaration::Function(Function {
                    name: accessor_names::cpp_accessor_name(prop_name, AccessorKind::Invoker),
                    signature: format!(
                        "({}) const -> {ret}",
                        param_types
                            .iter()
                            .enumerate()
                            .map(|(i, ty)| format!("{ty} arg_{i}"))
                            .join(", "),
                    ),
                    statements: Some(call_code),
                    ..Default::default()
                }),
            ));
        } else {
            let cpp_property_type = p.ty.cpp_type().expect("Invalid type in public properties");
            let prop_getter: Vec<String> = vec![format!(
                "return {}(live_preview.get_property(\"{prefix}{prop_name}\"));",
                convert_from_value_fn(&p.ty)
            )];
            declarations.push((
                Access::Public,
                Declaration::Function(Function {
                    name: accessor_names::cpp_accessor_name(prop_name, AccessorKind::Getter),
                    signature: format!("() const -> {cpp_property_type}"),
                    statements: Some(prop_getter),
                    ..Default::default()
                }),
            ));

            if !p.read_only() {
                let prop_setter: Vec<String> = vec![
                    "using slint::private_api::live_preview::into_slint_value;".into(),
                    format!(

View on GitHub (pinned to 3a7e700487)