{"record":{"id":"f2f34020398a05ce","repo":"vitest-dev/vitest","slug":"name-value-must-be-types-join-or-recei","errorCode":null,"errorMessage":"${name} value must be ${types.join(' or ')}, received \"${receivedType}\"","messagePattern":"(.+?) value must be (.+?), received \"(.+?)\"","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/helpers.ts","lineNumber":47,"sourceCode":"  const stackTrace = err.stack || ''\n  Error.prepareStackTrace = prepareStackTrace\n  Error.stackTraceLimit = limit\n  return stackTrace\n}\n\nexport function notNullish<T>(v: T | null | undefined): v is NonNullable<T> {\n  return v != null\n}\n\nexport function assertTypes(\n  value: unknown,\n  name: string,\n  types: string[],\n): void {\n  const receivedType = typeof value\n  const pass = types.includes(receivedType)\n  if (!pass) {\n    throw new TypeError(\n      `${name} value must be ${types.join(' or ')}, received \"${receivedType}\"`,\n    )\n  }\n}\n\nexport function isPrimitive(value: unknown): boolean {\n  return (\n    value === null || (typeof value !== 'function' && typeof value !== 'object')\n  )\n}\n\nexport function slash(path: string): string {\n  return path.replace(/\\\\/g, '/')\n}\n\nconst postfixRE = /[?#].*$/\nexport function cleanUrl(url: string): string {\n  return url.replace(postfixRE, '')","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/utils/src/helpers.ts#L29-L65","documentation":"assertTypes is Vitest's runtime type-validation helper used across config parsing, plugin APIs, and option processing. It checks `typeof value` against an allow-list of type strings and throws a TypeError naming the field, the expected types, and the received type. It is the guard behind many 'X must be Y' configuration errors.","triggerScenarios":"Passing a value of the wrong JS type to a Vitest API that internally calls assertTypes — e.g. a non-function to a callback option, a non-string to a path option, or a non-boolean to a flag option.","commonSituations":"Vitest config (vitest.config.ts) with a mistyped field; passing wrong types to programmatic APIs like createVitest or coverage options; JSON config loaded with coerced string values where booleans/functions were expected.","solutions":["Read the error's `name` field to identify which option was rejected, then fix its value type in your config.","Check the Vitest docs or config type definitions for the expected type of that option.","If loading config from JSON/env vars, coerce values to the correct type before passing them in."],"exampleFix":"// before — coverage.thresholds passed as a number instead of object:\ncoverage: { thresholds: 80 }\n\n// after — correct shape:\ncoverage: { thresholds: { lines: 80 } }","handlingStrategy":"validation","validationCode":"import { assertTypes } from '@vitest/utils/helpers'\n\n// validate config values before passing to Vitest APIs:\nassertTypes(myCallback, 'onConsoleLog', ['function','undefined'])","typeGuard":"function isOfType<T extends string>(value: unknown, ...types: string[]): boolean {\n  return types.includes(typeof value)\n}","tryCatchPattern":null,"preventionTips":["Use the vitest.config.ts TypeScript types to catch type mismatches at compile time.","When loading config from env/JSON, coerce values explicitly to the expected type.","Run typecheck (pnpm typecheck) to catch config type errors before runtime."],"tags":["config","type-validation","typeof"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}