{"record":{"id":"219dc8dedfccce8d","repo":"can1357/oh-my-pi","slug":"invalid-index-signature-pattern-keydefinition","errorCode":null,"errorMessage":"invalid index signature pattern ${keyDefinition}","messagePattern":"invalid index signature pattern (.+?)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/ir.ts","lineNumber":1361,"sourceCode":"\t\t\t} else {\n\t\t\t\tif (Array.isArray(val) && val.length === 3 && val[1] === \"=\") {\n\t\t\t\t\tthrow new OmpTypeError(\"index signatures cannot specify a default\");\n\t\t\t\t}\n\t\t\t\tvalue = parseDef(val, resolve);\n\t\t\t\tif (isEmbedded(val) && val.hasDefault) {\n\t\t\t\t\tthrow new OmpTypeError(\"index signatures cannot specify a default\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst keyDefinition = originalKey.slice(1, -1);\n\t\t\tconst regex = /^\\/((?:\\\\.|[^\\\\/])*)\\/([dgimsuvy]*)$/.exec(keyDefinition);\n\t\t\tlet key: IR;\n\t\t\tif (regex === null) {\n\t\t\t\tkey = parseDef(keyDefinition, resolve);\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tkey = patternIR(new RegExp(regex[1], regex[2]));\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new OmpTypeError(`invalid index signature pattern ${keyDefinition}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst objectIndexes = indexes ?? { patterns: [] };\n\t\t\tindexes = objectIndexes;\n\t\t\tindexKeyKind(key, value, props, objectIndexes);\n\t\t\tif (simple && (!isSimpleIR(key) || !isSimpleIR(value))) simple = false;\n\t\t\tcontinue;\n\t\t}\n\t\tconst escapedOptional = typeof originalKey === \"string\" && originalKey.endsWith(\"\\\\?\");\n\t\tconst escapedMeta =\n\t\t\ttypeof originalKey === \"string\" &&\n\t\t\t(originalKey === \"\\\\+\" || originalKey === \"\\\\...\" || originalKey.startsWith(\"\\\\[\"));\n\t\tconst rawKey = escapedOptional\n\t\t\t? `${originalKey.slice(0, -2)}?`\n\t\t\t: escapedMeta\n\t\t\t\t? originalKey.slice(1)\n\t\t\t\t: originalKey;\n\t\tconst opt = typeof rawKey === \"string\" && !escapedOptional && !escapedMeta && rawKey.endsWith(\"?\");","sourceCodeStart":1343,"sourceCodeEnd":1379,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/ir.ts#L1343-L1379","documentation":"An index-signature key written as a /regex/ literal must compile; if new RegExp(regex[1], regex[2]) throws, parseObjectDefinition wraps that failure into this OmpTypeError naming the offending key definition. It means the pattern between the slashes is not a syntactically valid JavaScript regular expression.","triggerScenarios":"A bracketed object key of the form \"/pattern/flags\" where pattern contains an unterminated escape, an invalid group, or the flags string contains characters outside dgimsuvy — i.e. any input making the RegExp constructor throw inside the ir.ts index-signature branch.","commonSituations":"Hand-written regex keys in schema strings with a typo (unbalanced paren, stray backslash); invalid flag letters like /a/q or /a/gg; copying regexes with lookahead variants unsupported by the runtime.","solutions":["Fix the regex literal in the key so it compiles in new RegExp","Remove or correct invalid regex flags (allowed: d g i m s u v y)","If you meant a literal key, drop the surrounding slashes and escape special chars instead","Test the pattern in isolation with new RegExp(pattern, flags) before putting it in the schema"],"exampleFix":"// before\ntype({ \"[/^(id_|name)/guu]\": \"string\" }) // duplicate 'u' flag throws\n// after\ntype({ \"[/^(id_|name)/gu]\": \"string\" })","handlingStrategy":"validation","validationCode":"function validateRegexKey(keyDef) {\n  const m = /^\\/((?:\\\\.|[^\\\\/])*)\\/([dgimsuvy]*)$/.exec(keyDef);\n  if (m === null) return true; // not a regex literal, fine\n  try { new RegExp(m[1], m[2]); return true; } catch { return false; }\n}","typeGuard":"const isValidRegexKey = (k) => { const m = /^\\/((?:\\\\.|[^\\\\/])*)\\/([dgimsuvy]*)$/.exec(k); return m === null || (() => { try { new RegExp(m[1], m[2]); return true; } catch { return false; } })(); };","tryCatchPattern":"try { const T = type(def); } catch (e) {\n  if (String(e.message).startsWith(\"invalid index signature pattern\")) {\n    // surface the offending key to the schema author\n  } else throw e;\n}","preventionTips":["Test every regex key with new RegExp() before embedding it in a schema","Only use flags from the dgimsuvy set, each at most once","Escape slashes and backslashes inside pattern keys"],"tags":["omptype","regex","index-signature","schema-definition"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}