{"id":"9bb5e79cbf9f83a1","repo":"sindresorhus/is","slug":"expected-value-which-is-class-received-value-of","errorCode":null,"errorMessage":"Expected value which is `Class`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Class`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1532,"sourceCode":"// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertBoundFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isBoundFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('bound Function', value));\n\t}\n}\n\n/**\nNote: [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)\n*/\nexport function assertBuffer(value: unknown, message?: string): asserts value is NodeBuffer {\n\tif (!isBuffer(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Buffer', value));\n\t}\n}\n\nexport function assertClass<T>(value: unknown, message?: string): asserts value is Class<T> {\n\tif (!isClass(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Class', value));\n\t}\n}\n\nexport function assertDataView(value: unknown, message?: string): asserts value is DataView {\n\tif (!isDataView(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('DataView', value));\n\t}\n}\n\nexport function assertDate(value: unknown, message?: string): asserts value is Date {\n\tif (!isDate(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Date', value));\n\t}\n}\n\nexport function assertDirectInstanceOf<T>(instance: unknown, class_: Class<T>, message?: string): asserts instance is T {\n\tif (!isDirectInstanceOf(instance, class_)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('T', instance));","sourceCodeStart":1514,"sourceCodeEnd":1550,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1514-L1550","documentation":"Thrown by `assertClass()` when the value fails `isClass` — a function whose string form starts with `class` (native class syntax). It guarantees the value can be used with `new` as a proper constructor of type `Class<T>`.","triggerScenarios":"Calling `assert.class_(value)` with an instance instead of the class itself, a plain/arrow function, an ES5 constructor-function 'class', or a class transpiled down to a function by an old compilation target.","commonSituations":"Passing `new Foo()` where `Foo` was expected (or vice versa); TypeScript/Babel targeting ES5 turns `class` into `function`, so `isClass` fails at runtime even though the source uses class syntax; DI/plugin registries receiving factory functions instead of classes; default-export interop (`module.default` vs module) yielding the wrong value.","solutions":["Pass the class constructor itself, not an instance: `register(Foo)` not `register(new Foo())`.","Set your compile target to ES2015+ so class syntax survives transpilation.","If importing, check ESM/CJS interop — you may need `mod.default`.","If the API legitimately accepts factory functions, use `assert.function_` instead."],"exampleFix":"// before (tsconfig)\n{\"compilerOptions\": {\"target\": \"es5\"}}\n// after\n{\"compilerOptions\": {\"target\": \"es2020\"}}","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'function' || !/^\\s*class\\s/.test(Function.prototype.toString.call(value))) {\n  // not a class constructor — pass the class itself, not an instance or factory\n}","typeGuard":"function isClass(value: unknown): value is new (...args: any[]) => unknown {\n  return typeof value === 'function' && /^\\s*class[\\s{]/.test(Function.prototype.toString.call(value));\n}","tryCatchPattern":"try {\n  assert.class_(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // an instance or plain function was passed where a class was expected — pass MyClass, not new MyClass()\n  } else throw error;\n}","preventionTips":["Pass the constructor (MyClass), not an instance (new MyClass()) — the error message showing 'Object' is the tell","Detection relies on toString() starting with 'class' — transpilers that downlevel classes to functions (old TS/Babel targets) break this; set target ES2015+","Regular functions used as constructors won't pass — declare real class syntax"],"tags":["type-assertion","class","transpilation","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}