{"record":{"id":"358c11f39f4d79e9","repo":"can1357/oh-my-pi","slug":"generic-parameters-must-be-names-or-name-constra","errorCode":null,"errorMessage":"generic parameters must be names or [name, constraint] pairs","messagePattern":"generic parameters must be names or \\[name, constraint\\] pairs","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":3668,"sourceCode":"\t\t};\n\t}\n\n\ttype GenericParameterSpec = string | readonly [name: string, constraint: unknown];\n\n\t/** Build a generic directly from an angle-bracket declaration. */\n\texport function generic<const definition>(parameters: `<${string}>`, definition: definition): Generic;\n\t/** Build a curried generic from named, optionally constrained parameters. */\n\texport function generic(...parameters: readonly GenericParameterSpec[]): GenericBuilder;\n\texport function generic(...arguments_: readonly (GenericParameterSpec | unknown)[]): Generic | GenericBuilder {\n\t\tif (arguments_.length === 2 && typeof arguments_[0] === \"string\" && arguments_[0].trimStart().startsWith(\"<\")) {\n\t\t\treturn createRuntimeGeneric(parseGenericParameters(arguments_[0]), arguments_[1]);\n\t\t}\n\t\tconst parameters: GenericParameter[] = arguments_.map(parameter => {\n\t\t\tif (typeof parameter === \"string\") return { name: parameter.trim() };\n\t\t\tif (Array.isArray(parameter) && typeof parameter[0] === \"string\") {\n\t\t\t\treturn { name: parameter[0].trim(), constraintDef: parameter[1] };\n\t\t\t}\n\t\t\tthrow new OmpTypeError(\"generic parameters must be names or [name, constraint] pairs\");\n\t\t});\n\t\tvalidateGenericParameters(parameters);\n\t\treturn (definition: unknown) => createRuntimeGeneric(parameters, definition);\n\t}\n\n\t/** Untyped builder for runtime-assembled definitions. */\n\texport function raw(def: unknown): BaseType {\n\t\treturn makeType(parseDef(def), [], {}) as unknown as BaseType;\n\t}\n\n\t/**\n\t * Return a validation-only schema that emits `json` verbatim — even when\n\t * embedded in an object, array, or union.\n\t *\n\t * A `.toJsonSchema()` method override cannot survive nesting: a parent schema\n\t * emits each child's IR directly and never calls the child's method, so the\n\t * override silently disappears from the wire schema. This stores the override\n\t * on the IR instead.","sourceCodeStart":3650,"sourceCodeEnd":3686,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L3650-L3686","documentation":"When declaring a runtime generic via `type.generic(...)`, each parameter must be either a plain name string or a two-element array of `[name, constraintDefinition]`. Anything else (numbers, objects, nested arrays, empty arrays, non-string first element) cannot be interpreted as a parameter declaration and throws.","triggerScenarios":"Calling `type.generic(1, \"T\")`, `type.generic({ name: \"T\" })`, or `type.generic([])`; also `type.generic([\"T\"], ...)` where the outer argument was meant to be one parameter but arrived as a malformed pair like `[123, ...]`.","commonSituations":"Programmatically building generic declarations from config/JSON where parameters were stored as objects; porting ArkType keyword-style generic syntax incorrectly; typos leaving a parameter array with a non-string first slot.","solutions":["Pass plain strings: `type.generic(\"T\", \"U\", definition)`.","For constrained parameters pass `[\"T\", constraint]` pairs: `type.generic([\"T\", \"string\"], definition)`.","Validate/normalize any config-driven parameter list to strings or [string, def] pairs before calling."],"exampleFix":"// before\ntype.generic({ name: \"T\" }, \"T[]\")\n// after\ntype.generic(\"T\", \"T[]\")","handlingStrategy":"validation","validationCode":"const validParam = (p: unknown) => typeof p === 'string' || (Array.isArray(p) && typeof p[0] === 'string' && p.length === 2);","typeGuard":"type GenericParam = string | [string, unknown]; const isGenericParam = (p: unknown): p is GenericParam => typeof p === 'string' || (Array.isArray(p) && typeof p[0] === 'string');","tryCatchPattern":"try { const g = type.generic(...params, definition); } catch (e) { if (e instanceof OmpTypeError) normalizeParams(params); else throw e; }","preventionTips":["Normalize config-driven parameter lists to strings or [name, constraint] tuples before calling","Avoid object-shaped parameter descriptors — they are not supported","Keep parameter declarations as plain literals in source rather than derived data when possible"],"tags":["generics","schema","api-misuse","validation"],"backgroundTag":"invalid-generic-parameter","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}