{"record":{"id":"a382539119537860","repo":"can1357/oh-my-pi","slug":"unsupported-default-literal-in-this-src","errorCode":null,"errorMessage":"unsupported default literal in \"${this.#src}\"","messagePattern":"unsupported default literal in \"(.+?)\"","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/ir.ts","lineNumber":376,"sourceCode":"\t\tif (t?.t === \"op\" && t.v === v) {\n\t\t\tthis.#pos++;\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/** Full definition with optional trailing `= literal` default and/or `?` optional marker. */\n\tparseTop(): ParsedTop {\n\t\tconst ir = this.parseUnion();\n\t\tlet def: unknown;\n\t\tlet hasDefault = false;\n\t\tif (this.#eatOp(\"=\")) {\n\t\t\tconst t = this.#next();\n\t\t\tif (t.t === \"num\" || t.t === \"bigint\" || t.t === \"date\" || t.t === \"str\") def = t.v;\n\t\t\telse if (t.t === \"id\" && (t.v === \"true\" || t.v === \"false\")) def = t.v === \"true\";\n\t\t\telse if (t.t === \"id\" && t.v === \"null\") def = null;\n\t\t\telse if (t.t === \"id\" && t.v === \"undefined\") def = undefined;\n\t\t\telse throw new OmpTypeError(`unsupported default literal in \"${this.#src}\"`);\n\t\t\thasDefault = true;\n\t\t}\n\t\tconst optional = this.#eatOp(\"?\");\n\t\tthis.#expectEnd();\n\t\treturn { ir, def, hasDefault, optional };\n\t}\n\n\t#expectEnd(): void {\n\t\tif (this.#pos < this.#toks.length) {\n\t\t\tthrow new OmpTypeError(`trailing tokens in definition \"${this.#src}\"`);\n\t\t}\n\t}\n\n\tparseUnion(): IR {\n\t\tconst first = this.parseIntersection();\n\t\tif (!this.#eatOp(\"|\")) return first;\n\t\tconst members = [first, this.parseIntersection()];\n\t\twhile (this.#eatOp(\"|\")) members.push(this.parseIntersection());","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/ir.ts#L358-L394","documentation":"After a '= default' marker, parseTop only accepts literal tokens (num, bigint, date, str) or the identifiers true/false/null/undefined. Any other token (a keyword like 'string', an identifier, an operator) is rejected because defaults must be compile-time literals, not computed expressions or type references.","triggerScenarios":"Definitions like 'string=hello' (unquoted string), 'number=Math.PI', \"string='a' | 'b'=...\" with a non-literal after '=', or 'boolean=yes'.","commonSituations":"Writing defaults for string types without quotes ('string=abc' instead of \"string='abc'\"); referencing constants by name expecting runtime evaluation; pasting TS default-value syntax ('number = 5' with spaces is fine, but 'number=default' is not).","solutions":["Quote string defaults: \"string='abc'\" not 'string=abc'.","Use only literal forms after '=': numbers, 5n-style bigints, dates, quoted strings, true/false/null/undefined.","Compute the value in code and supply it through the API's runtime-default mechanism if a non-literal default is needed.","Check ordering: the '=' clause follows the whole union, so ensure the default token itself is a literal, not an expression."],"exampleFix":"// before\nschema.parse(\"string=hello\");\n// after\nschema.parse(\"string='hello'\");","handlingStrategy":"validation","validationCode":"function isValidDefault(d) {\n  return typeof d === \"number\" || typeof d === \"bigint\" || d instanceof Date ||\n    typeof d === \"string\" || typeof d === \"boolean\" || d === null || d === undefined;\n}","typeGuard":"function isLiteralDefault(v) {\n  return v === null || v === undefined || typeof v === \"boolean\" ||\n    typeof v === \"number\" || typeof v === \"bigint\" || typeof v === \"string\" || v instanceof Date;\n}","tryCatchPattern":"try {\n  const schema = parse(def);\n} catch (e) {\n  if (String(e.message).includes(\"unsupported default literal\")) {\n    // quote string defaults or supply the default via the runtime API\n  }\n  throw e;\n}","preventionTips":["Always quote string defaults: \"string='abc'\".","Remember the allowed default forms: num, bigint, date, quoted string, true/false/null/undefined.","Pass non-literal defaults through the API's value-based mechanism, not the string grammar."],"tags":["parser","default-value","schema-definition"],"backgroundTag":"invalid-default-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}