{"record":{"id":"d1cd0b1e395ca495","repo":"mobxjs/mobx","slug":"generated-new-constructor-for-class-clazz-id-na","errorCode":null,"errorMessage":"Generated new constructor for class ${clazz.id?.name}. But since the class does have a base class, it might be needed to revisit the arguments that are passed to `super()`","messagePattern":"Generated new constructor for class (.+?)\\. But since the class does have a base class, it might be needed to revisit the arguments that are passed to `super\\(\\)`","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/mobx-undecorate/src/undecorate.ts","lineNumber":462,"sourceCode":"            // @ts-ignore\n            initializeObservablesCall.expression.typeArguments = j.tsTypeParameterInstantiation([\n                j.tsTypeReference(j.identifier(clazz.id!.name)),\n                j.tsUnionType(\n                    // @ts-ignore\n                    privates.map(member => j.tsLiteralType(j.stringLiteral(member)))\n                )\n            ])\n        }\n\n        const needsSuper = !!clazz.superClass\n        let constructorIndex = clazz.body.body.findIndex(\n            member => j.ClassMethod.check(member) && member.kind === \"constructor\"\n        )\n\n        // create a constructor\n        if (constructorIndex === -1) {\n            if (needsSuper) {\n                warn(\n                    `Generated new constructor for class ${clazz.id?.name}. But since the class does have a base class, it might be needed to revisit the arguments that are passed to \\`super()\\``,\n                    clazz\n                )\n            }\n\n            let superClassName = j.Identifier.check(clazz.superClass)\n                ? clazz.superClass.name\n                : j.MemberExpression.check(clazz.superClass)\n                ? j.Identifier.check(clazz.superClass.property)\n                    ? clazz.superClass.property.name\n                    : \"\"\n                : \"\"\n\n            // if this clazz is a react component, we now that the constructor and super call have one argument, the props\n            let isReactComponent =\n                hasReact && [\"Component\", \"PureComponent\"].includes(superClassName)\n            let propsType = isReactComponent && clazz.superTypeParameters?.params[0]\n            const propsParam = j.identifier(\"props\")","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/mobxjs/mobx/blob/01211a698b64ea94de8e5f276ff8235fcf8ddf96/packages/mobx-undecorate/src/undecorate.ts#L444-L480","documentation":"When generating a constructor for a derived class (one with a superClass), the codemod inserts `super()` and the makeObservable annotations, but it cannot know what arguments the original base constructor expects. It warns so the developer reviews the generated super call.","triggerScenarios":"`createConstructor` runs on a class that (a) has decorated members requiring makeObservable, (b) has no existing constructor (`constructorIndex === -1`), and (c) extends a base class (`needsSuper === true`).","commonSituations":"Legacy MobX 4/5 codebases where decorated subclasses relied on decorators initializing fields without a constructor; after undecoration a constructor is synthesized and base-class constructor arguments must be supplied by hand.","solutions":["Review the generated constructor and pass the correct arguments to the inserted `super(...)` call.","If the base class requires no arguments, ignore the warning after verifying.","Alternatively, write the constructor yourself before running the codemod so the codemod only appends makeObservable to it."],"exampleFix":"// generated by codemod (warning)\nconstructor() { super(); makeObservable(this, {...}) }\n// after manual fix\nconstructor(options) { super(options); makeObservable(this, {...}) }","handlingStrategy":"validation","validationCode":"// detect subclasses with decorated members and no constructor before codemod\nconst derivedNoCtor = /class\\s+\\w+\\s+extends\\s+\\w+\\s*\\{(?![^}]*constructor)/.test(src)\nif (derivedNoCtor && /@\\w+/.test(src)) {\n  console.warn('Derived class will get a generated constructor; verify super() args after codemod')\n}","typeGuard":"function hasOwnConstructor(clazz) {\n  return clazz.body.body.some(m => m.type === 'ClassMethod' && m.kind === 'constructor')\n}","tryCatchPattern":null,"preventionTips":["Write explicit constructors in subclasses before undecorating","Check the base class constructor signature before migrating","Search codemod output for 'Generated new constructor' warnings and review super() calls"],"tags":["codemod","constructor","inheritance","mobx-undecorate"],"backgroundTag":"generated-constructor-super-args","analyzedSha":"01211a698b64ea94de8e5f276ff8235fcf8ddf96","analyzedAt":"2026-08-28T22:10:08.831Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}