{"record":{"id":"d18e257e6b012b53","repo":"slint-ui/slint","slug":"duplicated-function-name-cb-on-global-global","errorCode":null,"errorMessage":"Duplicated function name ${cb} on global ${global}","messagePattern":"Duplicated function name (.+?) on global (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"api/node/typescript/index.ts","lineNumber":598,"sourceCode":"                                                    globalName,\n                                                    cb,\n                                                    callback,\n                                                );\n                                            },\n                                            enumerable: true,\n                                        },\n                                    );\n                                }\n                            });\n\n                        instance!\n                            .definition()\n                            .globalFunctions(globalName)\n                            ?.forEach((cb) => {\n                                const functionName = translateName(cb);\n\n                                if (globalObject[functionName] !== undefined) {\n                                    console.warn(\n                                        \"Duplicated function name \" +\n                                            cb +\n                                            \" on global \" +\n                                            global,\n                                    );\n                                } else {\n                                    Object.defineProperty(\n                                        globalObject,\n                                        translateName(cb),\n                                        {\n                                            get() {\n                                                return function () {\n                                                    return instance!.invokeGlobal(\n                                                        globalName,\n                                                        cb,\n                                                        Array.from(arguments),\n                                                    );\n                                                };","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/slint-ui/slint/blob/3fd8f2ec03c2aa8a95d5f4b9daa299c7b8bf4016/api/node/typescript/index.ts#L580-L616","documentation":"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.","triggerScenarios":"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.","commonSituations":"Adding a helper function whose name duplicates an existing property in camelCase; mixed-style declarations after refactors or code generation.","solutions":["Rename the function or the colliding member so translated names differ.","Smoke-run and check the console for 'Duplicated function name' after edits.","Enforce one naming style (kebab-case) across globals in CI/review.","Confirm every expected function appears in the generated .d.ts for the global."],"exampleFix":"// before (.slint): function's camelCase key collides with a property\nexport global Api {\n    out property <bool> fetchUser;      // -> fetchUser\n    function fetch-user() -> string;    // -> fetchUser (collides)\n}\n\n// after: unique camelCase keys\nexport global Api {\n    out property <bool> userRequested;\n    function fetch-user() -> string;    // fetchUser is now unique\n}","handlingStrategy":"validation","validationCode":"const globalObj = (instance as any)[jsGlobalName];\nfor (const fn of instance.definition().globalFunctions(jsGlobalName) ?? []) {\n    const key = fn.replace(/-(\\w)/g, (_, c: string) => c.toUpperCase());\n    if (typeof globalObj[key] !== 'function') {\n        throw new Error(`function \"${fn}\" on global \"${jsGlobalName}\" is shadowed`);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check that a new function's translated name does not clash with existing properties/callbacks on the same global","Keep one naming convention per global and enforce it in review","Grep dev-run console output for 'Duplicated function name' after adding functions"],"tags":["typescript","node","naming","functions","globals"],"backgroundTag":"duplicate-identifier-collision","analyzedSha":"3fd8f2ec03c2aa8a95d5f4b9daa299c7b8bf4016","analyzedAt":"2026-08-19T23:23:16.610Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}