slint-ui/slint · warning

Duplicated function name ${cb} on global ${global}

Error message

Duplicated function name ${cb} on global ${global}

What it means

Functions declared on a .slint global are exposed as callable members on the global's JS object. If a function's translated name equals a key already defined on that object (a property, callback, or another function using the colliding spelling), the bindings warn 'Duplicated function name <cb> on global <global>' and do not define the function - calling it from JS yields undefined.

Source

Thrown at api/node/typescript/index.ts:598

                                                    globalName,
                                                    cb,
                                                    callback,
                                                );
                                            },
                                            enumerable: true,
                                        },
                                    );
                                }
                            });

                        instance!
                            .definition()
                            .globalFunctions(globalName)
                            ?.forEach((cb) => {
                                const functionName = translateName(cb);

                                if (globalObject[functionName] !== undefined) {
                                    console.warn(
                                        "Duplicated function name " +
                                            cb +
                                            " on global " +
                                            global,
                                    );
                                } else {
                                    Object.defineProperty(
                                        globalObject,
                                        translateName(cb),
                                        {
                                            get() {
                                                return function () {
                                                    return instance!.invokeGlobal(
                                                        globalName,
                                                        cb,
                                                        Array.from(arguments),
                                                    );
                                                };

View on GitHub (pinned to 3fd8f2ec03)

Solutions

  1. Rename the function or the colliding member so translated names differ.
  2. Smoke-run and check the console for 'Duplicated function name' after edits.
  3. Enforce one naming style (kebab-case) across globals in CI/review.
  4. Confirm every expected function appears in the generated .d.ts for the global.

Example fix

// before (.slint): function's camelCase key collides with a property
export global Api {
    out property <bool> fetchUser;      // -> fetchUser
    function fetch-user() -> string;    // -> fetchUser (collides)
}

// after: unique camelCase keys
export global Api {
    out property <bool> userRequested;
    function fetch-user() -> string;    // fetchUser is now unique
}
Defensive patterns

Strategy: validation

Validate before calling

const globalObj = (instance as any)[jsGlobalName];
for (const fn of instance.definition().globalFunctions(jsGlobalName) ?? []) {
    const key = fn.replace(/-(\w)/g, (_, c: string) => c.toUpperCase());
    if (typeof globalObj[key] !== 'function') {
        throw new Error(`function "${fn}" on global "${jsGlobalName}" is shadowed`);
    }
}

Prevention

When it happens

Trigger: On one global: function fetch-user() alongside property <bool> fetchUser; two functions or a function plus callback whose kebab and camel spellings both translate to the same key.

Common situations: Adding a helper function whose name duplicates an existing property in camelCase; mixed-style declarations after refactors or code generation.

Related errors


AI-assisted analysis of slint-ui/slint@3fd8f2ec03 (2026-08-19). Data as JSON: /api/errors/d18e257e6b012b53. Report an issue: GitHub.