{"record":{"id":"4b52db3de95d0372","repo":"can1357/oh-my-pi","slug":"unsupported-definition-string-def-was-typeo","errorCode":null,"errorMessage":"unsupported definition ${String(def)} (was ${typeof def})","messagePattern":"unsupported definition (.+?) \\(was (.+?)\\)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/ir.ts","lineNumber":1521,"sourceCode":"\t}\n\tif (Array.isArray(def)) {\n\t\tif (def.length === 3 && def[1] === \"=\") {\n\t\t\tthrow new OmpTypeError(\"A default may only be specified for an object property or tuple element\");\n\t\t}\n\t\treturn parseArrayExpression(def, resolve);\n\t}\n\tif (def instanceof RegExp) return patternIR(def);\n\tif (def instanceof Date) return { k: \"lit\", v: def };\n\tif (isEmbedded(def)) return embed(def);\n\tif (typeof def === \"function\") {\n\t\tconst resolved = Reflect.apply(def, undefined, []);\n\t\tif (!isEmbedded(resolved)) {\n\t\t\tthrow new OmpTypeError(`thunk must return a Type (was ${typeof resolved})`);\n\t\t}\n\t\treturn embed(resolved);\n\t}\n\tif (isObjectDefinition(def)) return parseObjectDefinition(def, resolve);\n\tthrow new OmpTypeError(`unsupported definition ${String(def)} (was ${typeof def})`);\n}\n\n/** Whether `ir` needs no construction-time normalization or morph analysis. */\nexport function isSimpleIR(ir: IR): boolean {\n\tconst cached = ir[kSimpleOwner] === ir ? ir[kSimple] : undefined;\n\tif (cached !== undefined) return cached;\n\tconst simple = scanSimpleIR(ir);\n\tir[kSimple] = simple;\n\tir[kSimpleOwner] = ir;\n\treturn simple;\n}\n\nfunction scanSimpleIR(ir: IR): boolean {\n\tswitch (ir.k) {\n\t\tcase \"intersection\":\n\t\tcase \"morph\":\n\t\tcase \"sub\":\n\t\tcase \"alias\":","sourceCodeStart":1503,"sourceCodeEnd":1539,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/ir.ts#L1503-L1539","documentation":"parseDef is the universal definition entrypoint: strings, arrays, RegExp, Date, embeddable types, thunks, and object definitions are all accepted. Anything falling through all branches — undefined, null, a number, a boolean, an arbitrary class instance — reaches the final throw, which echoes the value and its typeof so you can see what was passed.","triggerScenarios":"Calling type()/parseDef with a value outside the supported definition grammar: primitives like 42 or true, null/undefined (often from a failed lookup or optional chain), or a foreign schema object from another library.","commonSituations":"Config lookups returning undefined (missing env var, typo'd key) passed straight into type(); JSON-parsed schemas containing raw numbers; mixing another validator's (zod/yup) schema objects into omptype definitions; array holes or sparse defaults.","solutions":["Log the definition value (the message echoes it) to find where undefined/garbage originates","Convert primitives into valid defs, e.g. type(\"'42'\") for a literal or type(String(x)) for a def string","Validate inputs before passing them to type()","If integrating another schema library, convert it to an omptype definition first"],"exampleFix":"// before\nconst T = type(config.fieldType) // config.fieldType is undefined\n// after\nconst def = config.fieldType ?? \"string\"\nconst T = type(def)","handlingStrategy":"try-catch","validationCode":"function isSupportedDef(def) {\n  return typeof def === \"string\" || Array.isArray(def) || def instanceof RegExp\n    || def instanceof Date || typeof def === \"function\"\n    || (def !== null && typeof def === \"object\");\n}\nif (def === undefined || def === null || typeof def === \"number\" || typeof def === \"boolean\")\n  throw new Error(\"unsupported definition before calling type()\");","typeGuard":"const isSupportedDef = (d) => d != null && (typeof d === \"string\" || typeof d === \"object\" || typeof d === \"function\");","tryCatchPattern":"try { const T = type(def); } catch (e) {\n  if (String(e.message).startsWith(\"unsupported definition\")) {\n    // the message echoes the value and typeof — log it to find the bad input source\n  } else throw e;\n}","preventionTips":["Never pass raw numbers/booleans/null into type(); use literal string defs instead","Coalesce optional lookups (?? \"string\") before building types","Validate externally-supplied schema data before feeding it to the parser","Convert foreign-library schema objects to omptype definitions explicitly"],"tags":["omptype","schema-definition","invalid-input","undefined"],"backgroundTag":"unsupported-type-definition","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}