{"record":{"id":"b3f6497718978227","repo":"can1357/oh-my-pi","slug":"instanceof-operands-must-be-constructors","errorCode":null,"errorMessage":"instanceof operands must be constructors","messagePattern":"instanceof operands must be constructors","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":3576,"sourceCode":"\t\t},\n\t\tobject: {\n\t\t\tjson: Object.defineProperties(keywordSchema<unknown>(\"object.json\"), {\n\t\t\t\tstringify: {\n\t\t\t\t\tvalue: keywordSchema<string, unknown>(\"object.json.stringify\"),\n\t\t\t\t\tenumerable: true,\n\t\t\t\t},\n\t\t\t}),\n\t\t},\n\t\tunknown: { any: keywordSchema<unknown>(\"unknown.any\") },\n\t};\n\t/** Date instance validator. */\n\t// biome-ignore lint/suspicious/noShadowRestrictedNames: ArkType exposes this exact keyword.\n\texport const Date = makeType<globalThis.Date>({ k: \"instance\", ctor: globalThis.Date, expected: \"a Date\" }, [], {});\n\n\t/** Validate instances of `ctor`. */\n\texport function instanceOf<const ctor extends Constructor>(ctor: ctor): FluentType<Constructed<ctor>> {\n\t\tif (typeof ctor !== \"function\" || ctor.prototype === undefined) {\n\t\t\tthrow new OmpTypeError(\"instanceof operands must be constructors\");\n\t\t}\n\t\tconst name = Reflect.get(ctor, \"name\");\n\t\tconst expected =\n\t\t\tctor.prototype === Error.prototype\n\t\t\t\t? \"an Error\"\n\t\t\t\t: typeof name === \"string\" && name.length > 0\n\t\t\t\t\t? `an instance of ${name}`\n\t\t\t\t\t: \"an instance\";\n\t\treturn makeType<Constructed<ctor>>({ k: \"instance\", ctor, expected }, [], {});\n\t}\n\n\t/** Validate one exact unit value. */\n\texport function unit<const value>(value: value): FluentType<value> {\n\t\treturn makeType<value>({ k: \"lit\", v: value }, [], {});\n\t}\n\n\t/** Union of literal values from a runtime array. */\n\texport function enumerated<const values extends readonly unknown[]>(...values: values): FluentType<values[number]> {","sourceCodeStart":3558,"sourceCodeEnd":3594,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L3558-L3594","documentation":"`type.instanceOf(ctor)` validates that its argument is an actual constructor function — something invokable with `new` and having a prototype. Passing a non-function, arrow function, or a bound function with `undefined` prototype cannot be used for `instanceof` checks, so omptype throws.","triggerScenarios":"Calling `type.instanceOf(SomeArrowFn)`, `type.instanceOf({})`, `type.instanceOf(obj.bind(...))` (bound functions have no `.prototype`), or passing a class imported as `undefined` due to a circular import.","commonSituations":"Circular imports leaving a class undefined at module-init time when the schema is built at top level; accidentally passing an instance instead of its class (`type.instanceOf(new Date())`); classes defined in a different module graph not yet loaded.","solutions":["Pass the class/constructor itself: `type.instanceOf(Date)`, not an instance.","Defer schema construction until the class module is fully loaded (avoid circular-import init-time construction).","For bound or arrow constructs, use a regular class or `type(() => v instanceof Target)` predicate instead."],"exampleFix":"// before\ntype.instanceOf(new Date())\n// after\ntype.instanceOf(Date)","handlingStrategy":"validation","validationCode":"function isConstructor(v: unknown): boolean { return typeof v === 'function' && v.prototype !== undefined; }","typeGuard":"const isCtor = (v: unknown): v is abstract new (...args: never[]) => unknown => typeof v === 'function' && v.prototype !== undefined;","tryCatchPattern":"try { const t = type.instanceOf(maybeCtor); } catch (e) { if (e instanceof OmpTypeError) deferSchemaConstruction(); else throw e; }","preventionTips":["Pass classes, never instances or bound functions","Avoid constructing instanceof schemas at module init when the class comes from a circular import","Remember bound functions and arrows have no .prototype and cannot be used"],"tags":["schema","instanceof","constructor","validation"],"backgroundTag":"instanceof-requires-constructor","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}