{"record":{"id":"8fdcb49ded64f023","repo":"can1357/oh-my-pi","slug":"a-default-may-only-be-specified-for-an-object-prop","errorCode":null,"errorMessage":"A default may only be specified for an object property or tuple element","messagePattern":"A default may only be specified for an object property or tuple element","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/ir.ts","lineNumber":1497,"sourceCode":"\tconst object: IR = {\n\t\tk: \"object\",\n\t\tprops,\n\t\tindex: indexes?.string,\n\t\tsymbolIndex: indexes?.symbol,\n\t\tpatternIndexes: indexes === undefined || indexes.patterns.length === 0 ? undefined : indexes.patterns,\n\t\textras,\n\t};\n\tobject[kSimple] = simple;\n\tobject[kSimpleOwner] = object;\n\treturn object;\n}\n\n/** Parse a definition, optionally resolving names from an enclosing scope. */\nexport function parseDef(def: unknown, resolve?: AliasResolver): IR {\n\tif (typeof def === \"string\") {\n\t\tconst parsed = parseStringDef(def, resolve);\n\t\tif (parsed.hasDefault) {\n\t\t\tthrow new OmpTypeError(\"A default may only be specified for an object property or tuple element\");\n\t\t}\n\t\tif (parsed.optional) {\n\t\t\tthrow new OmpTypeError(`optional \"?\" marker is only valid on object property values`);\n\t\t}\n\t\treturn parsed.ir;\n\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)) {","sourceCodeStart":1479,"sourceCodeEnd":1515,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/ir.ts#L1479-L1515","documentation":"When parseDef parses a string definition (or array expression) it rejects any result that carries a default: defaults are only meaningful in positions that map to a storage slot — an object property or a tuple element. A bare top-level definition like \"string=foo\" has nothing to attach the default to, so it throws.","triggerScenarios":"Calling parseDef (directly or via type()) with a string def that parseStringDef parses with hasDefault set, or an array def of length 3 with \"=\" at index 1 — i.e. a default written outside an object property or tuple element position.","commonSituations":"Copying a property's string including its \"=value\" suffix into a standalone type; passing a defaulted expression where a plain type is expected (function parameter, union member, alias body).","solutions":["Remove the \"=default\" suffix from the standalone definition","Wrap it as an object property or tuple element where defaults are allowed","Split into the plain type plus a separate default value handled by your own code"],"exampleFix":"// before\nconst T = type(\"string='hello'\")\n// after\nconst T = type({ key: \"string='hello'\" })","handlingStrategy":"type-guard","validationCode":"function assertNoTopLevelDefault(def) {\n  if (typeof def === \"string\" && /=/.test(def.split(\"|\")[0])) {\n    // conservative check for \"=default\" suffix outside property position\n    throw new Error(\"remove the =default from the standalone definition\");\n  }\n  if (Array.isArray(def) && def.length === 3 && def[1] === \"=\") {\n    throw new Error(\"defaulted array form only valid as property/tuple value\");\n  }\n}","typeGuard":"const isDefaultedForm = (d) => (Array.isArray(d) && d.length === 3 && d[1] === \"=\");","tryCatchPattern":"try { const T = type(def); } catch (e) {\n  if (e.message.includes(\"A default may only be specified\")) {\n    // move def into an object property or tuple element, or strip the default\n  } else throw e;\n}","preventionTips":["Only write \"=default\" inside object property values or tuple elements","When lifting property values into standalone constants, strip the default segment","Review copy-pasted property strings for trailing \"=...\" suffixes"],"tags":["omptype","schema-definition","default-value"],"backgroundTag":"invalid-default-location","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}