vitest-dev/vitest · error · TypeError
value must be , received
Error message
${name} value must be ${types.join(' or ')}, received "${receivedType}" What it means
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.
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.
Example fix
// before — coverage.thresholds passed as a number instead of object:
coverage: { thresholds: 80 }
// after — correct shape:
coverage: { thresholds: { lines: 80 } } Defensive patterns
Strategy: validation
Validate before calling
import { assertTypes } from '@vitest/utils/helpers'
// validate config values before passing to Vitest APIs:
assertTypes(myCallback, 'onConsoleLog', ['function','undefined']) Type guard
function isOfType<T extends string>(value: unknown, ...types: string[]): boolean {
return types.includes(typeof value)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Access denied to " ". See Vite config documentation for…
- All browser instances within a project must use the same…
- "browser.instances" was set in the config, but the array is…
- browser is not initialized
- Browser Mode requires the "provider" to always be specified.
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/f2f34020398a05ce.
Report an issue: GitHub.
Appendix: source
Thrown at packages/utils/src/helpers.ts:47
const stackTrace = err.stack || ''
Error.prepareStackTrace = prepareStackTrace
Error.stackTraceLimit = limit
return stackTrace
}
export function notNullish<T>(v: T | null | undefined): v is NonNullable<T> {
return v != null
}
export function assertTypes(
value: unknown,
name: string,
types: string[],
): void {
const receivedType = typeof value
const pass = types.includes(receivedType)
if (!pass) {
throw new TypeError(
`${name} value must be ${types.join(' or ')}, received "${receivedType}"`,
)
}
}
export function isPrimitive(value: unknown): boolean {
return (
value === null || (typeof value !== 'function' && typeof value !== 'object')
)
}
export function slash(path: string): string {
return path.replace(/\\/g, '/')
}
const postfixRE = /[?#].*$/
export function cleanUrl(url: string): string {
return url.replace(postfixRE, '')View on GitHub (pinned to 1fa9837ec2)