{"record":{"id":"5ee99f48d24304af","repo":"jquense/yup","slug":"a-method-name-must-be-provided","errorCode":null,"errorMessage":"A Method name must be provided","messagePattern":"A Method name must be provided","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/index.ts","lineNumber":59,"sourceCode":"  DefaultThunk,\n} from './types';\n\nfunction addMethod<T extends ISchema<any>>(\n  schemaType: (...arg: any[]) => T,\n  name: string,\n  fn: (this: T, ...args: any[]) => T,\n): void;\nfunction addMethod<T extends abstract new (...args: any) => ISchema<any>>(\n  schemaType: T,\n  name: string,\n  fn: (this: InstanceType<T>, ...args: any[]) => InstanceType<T>,\n): void;\nfunction addMethod(schemaType: any, name: string, fn: any) {\n  if (!schemaType || !isSchema(schemaType.prototype))\n    throw new TypeError('You must provide a yup schema constructor function');\n\n  if (typeof name !== 'string')\n    throw new TypeError('A Method name must be provided');\n  if (typeof fn !== 'function')\n    throw new TypeError('Method function must be provided');\n\n  schemaType.prototype[name] = fn;\n}\n\nexport type AnyObjectSchema = ObjectSchema<any, any, any, any>;\n\nexport type CastOptions = Omit<BaseCastOptions, 'path' | 'resolved'>;\n\nexport type {\n  AnyMessageParams,\n  AnyObject,\n  InferType,\n  InferType as Asserts,\n  ISchema,\n  Message,\n  MessageParams,","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/jquense/yup/blob/ff31eee8a2b10c938bb3a22544d9e33957a8cf01/src/index.ts#L41-L77","documentation":"addMethod()'s second argument is the method name that will be assigned onto the schema prototype, so it must be a string. If it is missing, undefined, or a non-string (number, symbol, object), addMethod throws 'A Method name must be provided'. This happens after the schemaType check, so the target constructor was valid.","triggerScenarios":"yup.addMethod(yup.string, undefined, fn), addMethod(yup.date, 42, fn), or name coming from a config/destructured variable that is undefined.","commonSituations":"Renamed exports breaking a constant that held the method name; calling addMethod with arguments swapped (schemaType, fn, name); generated plugin code with missing metadata.","solutions":["Pass the method name as a string: yup.addMethod(yup.string, 'myName', fn).","Check argument order — the signature is (schemaType, name, fn).","Validate the name variable is defined before invoking addMethod."],"exampleFix":"// before\nyup.addMethod(yup.string, fn, 'phone')\n// after\nyup.addMethod(yup.string, 'phone', fn)","handlingStrategy":"validation","validationCode":"const addNamedMethod = (type, name, fn) => {\n  if (typeof name !== 'string' || name === '') throw new TypeError('method name must be a non-empty string');\n  yup.addMethod(type, name, fn);\n};","typeGuard":"const isMethodName = (v) => typeof v === 'string' && v.length > 0;","tryCatchPattern":null,"preventionTips":["Keep the (schemaType, name, fn) argument order fixed — use named constants.","Never compute the name from optional config without a default.","Define method names in one shared module to avoid typos and undefined values."],"tags":["yup","addmethod","argument","type-error"],"backgroundTag":"invalid-add-method-target","analyzedSha":"ff31eee8a2b10c938bb3a22544d9e33957a8cf01","analyzedAt":"2026-08-31T21:51:03.773Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}