{"record":{"id":"398171ee019a5cf8","repo":"facebook/lexical","slug":"name-must-implement-static-method-method","errorCode":null,"errorMessage":"${name} must implement static \"${method}\" method","messagePattern":"(.+?) must implement static \"(.+?)\" method","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/lexical/src/LexicalEditor.ts","lineNumber":1037,"sourceCode":"            name,\n          );\n        } else if (replace) {\n          console.warn(\n            `Override for ${name} specifies 'replace' without 'withKlass'. 'withKlass' will be required in a future version.`,\n          );\n        }\n        if (\n          name !== 'RootNode' &&\n          nodeType !== 'root' &&\n          nodeType !== 'artificial' &&\n          // This is mostly for the unit test suite which\n          // uses LexicalNode in an otherwise incorrect way\n          // by mocking its static getType\n          klass !== LexicalNode\n        ) {\n          (['getType', 'clone'] as const).forEach(method => {\n            if (!hasOwnStaticMethod(klass, method)) {\n              console.warn(`${name} must implement static \"${method}\" method`);\n            }\n          });\n          if (!hasOwnStaticMethod(klass, 'importJSON')) {\n            console.warn(\n              `${name} should implement \"importJSON\" method to ensure JSON and default HTML serialization works as expected`,\n            );\n          }\n        }\n      }\n      const type = klass.getType();\n      const transforms = getTransformSetFromKlass(klass);\n      registeredNodes.set(type, {\n        exportDOM: html && html.export ? html.export.get(klass) : undefined,\n        klass,\n        replace,\n        replaceWithKlass,\n        sharedNodeState: createSharedNodeState(nodes[i]),\n        transforms,","sourceCodeStart":1019,"sourceCodeEnd":1055,"githubUrl":"https://github.com/facebook/lexical/blob/76a22dcba981b46119fcec45f935270707e26a57/packages/lexical/src/LexicalEditor.ts#L1019-L1055","documentation":"When createEditor processes the `nodes` array, each node class must define its own static `getType` and `clone` methods (inherited ones are rejected via hasOwnStaticMethod, except LexicalNode itself). If a class lacks one, Lexical logs this warning; such a node will misbehave (getType/clone falls back to the parent's, producing wrong types or broken cloning).","triggerScenarios":"Passing a custom node class in createEditor({nodes: [...]}) (or nestedEditor node arrays) that extends a Lexical node but does not declare `static getType()` or `static clone()` itself — e.g. a mock or a class relying on inheritance.","commonSituations":"Hand-rolled CustomNode extending TextNode/ElementNode with only instance methods; test mocks subclassing LexicalNode; classes compiled/transpiled in a way that drops statics; older node definitions predating the clone() requirement.","solutions":["Add `static getType(): string` returning a unique type string to the node class.","Add `static clone(node): SameNode` returning a new instance cloned from `node`.","Ensure the class is registered in the editor's nodes array only once and truly extends LexicalNode.","If this is a mock in tests, define the statics explicitly instead of relying on the base class."],"exampleFix":"// before\nclass MyNode extends TextNode {}\n// after\nclass MyNode extends TextNode {\n  static getType(): string {\n    return 'my-node';\n  }\n  static clone(node: MyNode): MyNode {\n    return new MyNode(node.__text, node.__key);\n  }\n}","handlingStrategy":"type-guard","validationCode":"function assertNodeStatics(klass: any) {\n  for (const m of ['getType', 'clone']) {\n    if (!Object.prototype.hasOwnProperty.call(klass, m)) {\n      throw new Error(`${klass.name} must implement static \"${m}\"`);\n    }\n  }\n}","typeGuard":"function hasOwnStaticMethod(klass: Function, method: string): boolean {\n  return Object.prototype.hasOwnProperty.call(klass, method) && typeof (klass as any)[method] === 'function';\n}","tryCatchPattern":null,"preventionTips":["Always define static getType and static clone on every custom node class — never rely on inheritance.","Add a unit test that iterates your nodes array and asserts hasOwnStaticMethod for getType/clone.","Prefer the $create factory + class template from the docs when creating new nodes."],"tags":["console-warning","node-definition","api-misuse","custom-node"],"backgroundTag":"missing-required-method","analyzedSha":"76a22dcba981b46119fcec45f935270707e26a57","analyzedAt":"2026-08-31T21:45:54.792Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}