{"record":{"id":"3c6e3cb51a9f8234","repo":"can1357/oh-my-pi","slug":"generic-expects-parameters-length-arguments-re","errorCode":null,"errorMessage":"generic expects ${parameters.length} arguments (received ${arguments_.length})","messagePattern":"generic expects (.+?) arguments \\(received (.+?)\\)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":2642,"sourceCode":"\tdefinition: unknown,\n\touter?: AliasResolver,\n\tvalidateBody = true,\n): RuntimeGeneric {\n\tconst constraintResolve = ((name: string) => outer?.(name)) as AliasResolver;\n\tconstraintResolve.hasGeneric = outer?.hasGeneric;\n\tconstraintResolve.generic = outer?.generic;\n\tvalidateGenericParameters(parameters);\n\tconst placeholders = parameters.map(parameter =>\n\t\tparameter.constraintDef === undefined\n\t\t\t? ({ k: \"unknown\" } as IR)\n\t\t\t: parseDef(parameter.constraintDef, constraintResolve),\n\t);\n\tif (validateBody) genericBodyIR(parameters, definition, placeholders, outer);\n\tconst meta: GenericMeta = {\n\t\tparameters,\n\t\tinstantiateIR(arguments_) {\n\t\t\tif (arguments_.length !== parameters.length) {\n\t\t\t\tthrow new OmpTypeError(`generic expects ${parameters.length} arguments (received ${arguments_.length})`);\n\t\t\t}\n\t\t\tfor (let index = 0; index < parameters.length; index++) {\n\t\t\t\tconst parameter = parameters[index];\n\t\t\t\tif (parameter.constraintDef === undefined) continue;\n\t\t\t\tconst constraint = parseDef(parameter.constraintDef, constraintResolve);\n\t\t\t\tif (!isSubtype(arguments_[index], constraint)) {\n\t\t\t\t\tthrow new OmpTypeError(`${parameter.name} must be assignable to its constraint`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn genericBodyIR(parameters, definition, arguments_, outer);\n\t\t},\n\t};\n\tconst generic = Object.assign(\n\t\t(...arguments_: readonly unknown[]) =>\n\t\t\tmakeType(\n\t\t\t\tmeta.instantiateIR(arguments_.map(argument => parseGenericArgument(argument, outer))),\n\t\t\t\tEMPTY_STEPS,\n\t\t\t\tEMPTY_META,","sourceCodeStart":2624,"sourceCodeEnd":2660,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L2624-L2660","documentation":"instantiateIR() checks argument count against the declared generic parameter count and throws OmpTypeError on mismatch. Generics are exact-arity: you must supply one type argument per declared parameter when instantiating.","triggerScenarios":"Calling the generic with too few or too many type arguments, e.g. generic('<K, V>', ...) instantiated with only one argument, or zero arguments via .instantiate()/calling without args.","commonSituations":"Arity changed after refactoring the parameter list but call sites weren't updated; spreading an array of arguments that is empty or mis-collected; forgetting that a two-parameter generic needs both arguments.","solutions":["Pass exactly as many type arguments as declared parameters: G('string', 'number') for '<T, U>'","Update all instantiation sites after changing the generic's parameter list","Inspect the error's received count to see how many arguments actually arrived and fix the spread","For optional parameters, provide an explicit concrete type instead of omitting the argument"],"exampleFix":"// before\nconst G = generic('<K, V>', 'record<K, V>');\nconst r = G('string'); // throws: expects 2\n// after\nconst r = G('string', 'number');","handlingStrategy":"type-guard","validationCode":"function assertArity(params: readonly unknown[], declared: number) {\n  if (params.length !== declared) {\n    throw new Error(`generic expects ${declared} arguments (received ${params.length})`);\n  }\n}","typeGuard":"function hasExactArity<const N extends number>(args: readonly unknown[], n: N): args is { length: N } & readonly unknown[] {\n  return args.length === n;\n}","tryCatchPattern":"try {\n  const inst = G(...typeArgs);\n} catch (err) {\n  if (err instanceof OmpTypeError && /generic expects \\d+ arguments/.test(err.message)) {\n    throw new Error(`Check call sites of generic \"${genericName}\": ${err.message}`);\n  }\n  throw err;\n}","preventionTips":["Keep a single named constant for each generic's arity and share it with call sites","Re-grep instantiation sites whenever a parameter list changes","Spread arrays carefully — an empty array means zero arguments"],"tags":["generics","arity","schema","omptype"],"backgroundTag":"generic-arity-mismatch","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}