{"record":{"id":"e8869c915c50b073","repo":"microsoft/TypeScript","slug":"class-extends-value-string-b-is-not-a-construc","errorCode":null,"errorMessage":"Class extends value ${String(b)} is not a constructor or null","messagePattern":"Class extends value (.+?) is not a constructor or null","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/compiler/factory/emitHelpers.ts","lineNumber":950,"sourceCode":"// ES2015 Helpers\r\n\r\nconst extendsHelper: UnscopedEmitHelper = {\r\n    name: \"typescript:extends\",\r\n    importName: \"__extends\",\r\n    scoped: false,\r\n    priority: 0,\r\n    text: `\r\n            var __extends = (this && this.__extends) || (function () {\r\n                var extendStatics = function (d, b) {\r\n                    extendStatics = Object.setPrototypeOf ||\r\n                        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n                        function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n                    return extendStatics(d, b);\r\n                };\r\n\r\n                return function (d, b) {\r\n                    if (typeof b !== \"function\" && b !== null)\r\n                        throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n                    extendStatics(d, b);\r\n                    function __() { this.constructor = d; }\r\n                    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n                };\r\n            })();`,\r\n};\r\n\r\nconst templateObjectHelper: UnscopedEmitHelper = {\r\n    name: \"typescript:makeTemplateObject\",\r\n    importName: \"__makeTemplateObject\",\r\n    scoped: false,\r\n    priority: 0,\r\n    text: `\r\n            var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {\r\n                if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n                return cooked;\r\n            };`,\r\n};\r","sourceCodeStart":932,"sourceCodeEnd":968,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/compiler/factory/emitHelpers.ts#L932-L968","documentation":"`__extends` downlevels class heritage for ES5 targets. It throws if the base value `b` is neither a function nor null, because only a constructor (or null) is a legal class-extends target.","triggerScenarios":"`class X extends Y` where Y evaluates at runtime to a non-function, non-null value: a number, string, plain object, or `undefined`.","commonSituations":"Circular import causing the base to be undefined at class-evaluation time; a mixin computed to a non-function; extending a const before its declaration (TDZ-like effect in transpiled output).","solutions":["Ensure the extended expression evaluates to a constructor (class/function) or null.","Resolve circular imports so the base is fully initialized before the subclass definition runs.","If extending null intentionally, write `extends null` explicitly."],"exampleFix":"// before\n// a.js: export const Base = 5;        // not a constructor\n// b.js: import { Base } from \"./a\"; class Sub extends Base {}  // throws\n\n// after\n// a.js: export class Base {}\n// b.js: import { Base } from \"./a\"; class Sub extends Base {}","handlingStrategy":"type-guard","validationCode":"function assertExtensible(base: unknown): void {\n  if (typeof base !== \"function\" && base !== null) {\n    throw new TypeError(`Class extends value ${String(base)} is not a constructor or null`);\n  }\n}","typeGuard":"function isConstructorOrNull(v: unknown): v is (new (...args: any[]) => any) | null {\n  return v === null || typeof v === \"function\";\n}","tryCatchPattern":null,"preventionTips":["Break circular imports so the base is initialized before the subclass is evaluated.","Validate mixins return a function before extending them.","Use `extends null` explicitly when extending null."],"tags":["classes","inheritance","runtime","emit-helpers"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}