{"record":{"id":"deabce8624acf728","repo":"discordjs/discord.js","slug":"expected-prop-to-be-a-function-received-type","errorCode":null,"errorMessage":"Expected ${prop} to be a function, received ${typeof descriptor.value} instead.","messagePattern":"Expected (.+?) to be a function, received (.+?) instead\\.","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/structures/src/Mixin.ts","lineNumber":84,"sourceCode":"\t\t\t}\n\n\t\t\tif (prototype[kMixinToJSON]) {\n\t\t\t\tenrichToJSONs.push(prototype[kMixinToJSON]);\n\t\t\t}\n\n\t\t\t// Copy instance methods and setters / getters\n\t\t\tconst originalDescriptors = Object.getOwnPropertyDescriptors(prototype);\n\t\t\tconst usingDescriptors: { [prop: string]: PropertyDescriptor } = {};\n\t\t\tfor (const [prop, descriptor] of Object.entries(originalDescriptors)) {\n\t\t\t\t// Drop constructor\n\t\t\t\tif (['constructor'].includes(prop)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Special case for optimize function, we want to combine these\n\t\t\t\tif (prop === OptimizeDataPropertyName) {\n\t\t\t\t\tif (typeof descriptor.value !== 'function')\n\t\t\t\t\t\tthrow new RangeError(`Expected ${prop} to be a function, received ${typeof descriptor.value} instead.`);\n\t\t\t\t\tdataOptimizations.push(descriptor.value);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Shouldn't be anything other than these without being instantiated, but just in case\n\t\t\t\tif (\n\t\t\t\t\ttypeof descriptor.get !== 'undefined' ||\n\t\t\t\t\ttypeof descriptor.set !== 'undefined' ||\n\t\t\t\t\ttypeof descriptor.value === 'function'\n\t\t\t\t) {\n\t\t\t\t\tusingDescriptors[prop] = descriptor;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tObject.defineProperties(destination.prototype, usingDescriptors);\n\t\t}\n\t}\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/structures/src/Mixin.ts#L66-L102","documentation":"The Mixin utility merges classes/objects; when it encounters the special optimization-data property (OptimizeDataPropertyName) it requires its value to be a function, and throws this RangeError otherwise.","triggerScenarios":"Applying Mixin to a class or object whose optimization data property (e.g. [OptimizeDataPropertyName] / special resolve-style property) is set to a non-function value like an array or object.","commonSituations":"Manually copying static properties between classes, using a mixin pattern that stores optimization data as data rather than a function, or upgrading @discordjs/structures-adjacent packages with mismatched shapes.","solutions":["Ensure the optimization property is defined as a function (e.g. a static resolver method)","Remove the property if you did not intend to attach optimization data","Check which mixin source class carries the malformed property and fix its definition"],"exampleFix":"// before\nclass Foo { static [OptimizeDataPropertyName] = ['a', 'b']; }\n// after\nclass Foo { static [OptimizeDataPropertyName] = () => ['a', 'b']; }","handlingStrategy":"validation","validationCode":"if (OptimizeDataPropertyName in MixedClass && typeof MixedClass[OptimizeDataPropertyName] !== 'function') {\n  throw new Error('optimization data property must be a function before Mixin()');\n}","typeGuard":"function hasFunctionOptimizeData(cls: unknown): boolean {\n  return typeof cls !== 'function' || !(OptimizeDataPropertyName in cls) || typeof (cls as any)[OptimizeDataPropertyName] === 'function';\n}","tryCatchPattern":"try {\n  const Mixed = Mixin(Base, Feature);\n} catch (err) {\n  if (err instanceof RangeError && err.message.includes('to be a function')) {\n    // inspect the optimization-data property on the inputs\n  }\n}","preventionTips":["Keep optimization-data properties as functions on mixin inputs","Avoid manually copying statics between classes with Object.assign","Pin matching versions of packages sharing the Mixin utility"],"tags":["mixin","types","library-internals"],"backgroundTag":"invalid-argument-type","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}