{"id":"b1d1e8c6b775c894","repo":"jestjs/jest","slug":"option-path-option-must-be-of-type","errorCode":null,"errorMessage":"  Option \"${path}.${option}\" must be of type:\n    ${validTypes}\n  but instead received:\n    ${getType(received)}\n\n  Example:\n${formatExamples(option, conditions)}","messagePattern":"  Option \"(.+?)\\.(.+?)\" must be of type:\n    (.+?)\n  but instead received:\n    (.+?)\n\n  Example:\n(.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"packages/jest-validate/src/errors.ts","lineNumber":37,"sourceCode":"  path?: Array<string>,\n): void => {\n  const conditions = getValues(defaultValue);\n  const validTypes: Array<string> = [...new Set(conditions.map(getType))];\n\n  const message = `  Option ${chalk.bold(\n    `\"${path && path.length > 0 ? `${path.join('.')}.` : ''}${option}\"`,\n  )} must be of type:\n    ${validTypes.map(e => chalk.bold.green(e)).join(' or ')}\n  but instead received:\n    ${chalk.bold.red(getType(received))}\n\n  Example:\n${formatExamples(option, conditions)}`;\n\n  const comment = options.comment;\n  const name = (options.title && options.title.error) || ERROR;\n\n  throw new ValidationError(name, message, comment);\n};\n\nfunction formatExamples(option: string, examples: Array<unknown>) {\n  return examples.map(\n    e => `  {\n    ${chalk.bold(`\"${option}\"`)}: ${chalk.bold(formatPrettyObject(e))}\n  }`,\n  ).join(`\n\n  or\n\n`);\n}\n","sourceCodeStart":19,"sourceCodeEnd":51,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-validate/src/errors.ts#L19-L51","documentation":"Thrown by `errorMessage` in jest-validate (errors.ts:24-37, throws as `ValidationError`) when a config option's value fails its type condition. The validator compares the received value's type against the set of types observed across the option's example/default values; on mismatch it prints the expected types, the received type, and a concrete example block.","triggerScenarios":"Setting a Jest config option to a value whose runtime type doesn't match any of the types present in the default/example config: e.g. coverageThreshold set to a string instead of object, testMatch set to a single string instead of an array of strings (testMatch is array-typed), coveragePathIgnorePatterns set to a single string instead of an array.","commonSituations":"Hand-typed jest.config.js where the shape doesn't match the docs; copy-pasting a single value where Jest wants an array (or vice versa); passing a function where a value is expected; environment-variable overrides coerced to the wrong type.","solutions":["Read the message's `must be of type` line and the example block - they name the exact shape expected.","Open the Jest config docs for the named option and match the documented type.","Run Jest with `--showConfig` or `--listTests` to surface validation before running tests.","If overriding via env vars (e.g. `--maxWorkers`), ensure CLI/coercion produces the right type."],"exampleFix":"// before\nmodule.exports = { coverageThreshold: { global: 'lines' } }; // 'lines' should be a number\n// after\nmodule.exports = { coverageThreshold: { global: { lines: 80 } } };","handlingStrategy":"validation","validationCode":"// Validate config types against the example/default before running Jest\nconst { validate } = require('jest-validate');\nvalidate(myConfig, { exampleConfig: defaultJestConfig, title: { warn: '', error: 'jest.config.js' } });","typeGuard":"const isObjectType = (v: unknown, t: 'object' | 'string' | 'number' | 'boolean' | 'function'): boolean =>\n  t === 'object' ? (typeof v === 'object' && v !== null && !Array.isArray(v)) : typeof v === t;","tryCatchPattern":null,"preventionTips":["Cross-check each option's type in the Jest config docs before writing it.","Use TypeScript-typed jest config (`/** @type {import('jest').Config} */`).","Run `jest --showConfig` to validate before executing the suite."],"tags":["jest-validate","config","type-error","user-error"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}