mobxjs/mobx · warning
Generated new constructor for class ${clazz.id?.name}. But s
Error message
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()` What it means
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.
Source
Thrown at packages/mobx-undecorate/src/undecorate.ts:462
// @ts-ignore
initializeObservablesCall.expression.typeArguments = j.tsTypeParameterInstantiation([
j.tsTypeReference(j.identifier(clazz.id!.name)),
j.tsUnionType(
// @ts-ignore
privates.map(member => j.tsLiteralType(j.stringLiteral(member)))
)
])
}
const needsSuper = !!clazz.superClass
let constructorIndex = clazz.body.body.findIndex(
member => j.ClassMethod.check(member) && member.kind === "constructor"
)
// create a constructor
if (constructorIndex === -1) {
if (needsSuper) {
warn(
`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()\``,
clazz
)
}
let superClassName = j.Identifier.check(clazz.superClass)
? clazz.superClass.name
: j.MemberExpression.check(clazz.superClass)
? j.Identifier.check(clazz.superClass.property)
? clazz.superClass.property.name
: ""
: ""
// if this clazz is a react component, we now that the constructor and super call have one argument, the props
let isReactComponent =
hasReact && ["Component", "PureComponent"].includes(superClassName)
let propsType = isReactComponent && clazz.superTypeParameters?.params[0]
const propsParam = j.identifier("props")View on GitHub (pinned to 01211a698b)
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.
Example fix
// generated by codemod (warning)
constructor() { super(); makeObservable(this, {...}) }
// after manual fix
constructor(options) { super(options); makeObservable(this, {...}) } Defensive patterns
Strategy: validation
Validate before calling
// detect subclasses with decorated members and no constructor before codemod
const derivedNoCtor = /class\s+\w+\s+extends\s+\w+\s*\{(?![^}]*constructor)/.test(src)
if (derivedNoCtor && /@\w+/.test(src)) {
console.warn('Derived class will get a generated constructor; verify super() args after codemod')
} Type guard
function hasOwnConstructor(clazz) {
return clazz.body.body.some(m => m.type === 'ClassMethod' && m.kind === 'constructor')
} Prevention
- 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
When it happens
Trigger: `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`).
Common situations: 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.
Related errors
- Expected a decorate call with two arguments
- Expected exactly one class declaration for '${target.name}'
- Failed to find mobx import, can't add makeObservable as depe
- Found multiple decorators, skipping..
- Found non-mobx decorator @${expr.name}
AI-assisted analysis of mobxjs/mobx@01211a698b (2026-08-28).
Data as JSON: /api/errors/d1cd0b1e395ca495.
Report an issue: GitHub.