{"record":{"id":"bac948dff8b41bf2","repo":"vitest-dev/vitest","slug":"bench-does-not-accept-options-as-the-third-arg","errorCode":null,"errorMessage":"`bench()` does not accept options as the third argument. Pass options as the second argument instead: `bench(name, options, fn)`.","messagePattern":"`bench\\(\\)` does not accept options as the third argument\\. Pass options as the second argument instead: `bench\\(name, options, fn\\)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/benchmark.ts","lineNumber":574,"sourceCode":"  }\n\n  return bench\n}\n\nfunction formatModuleId(moduleId: string, root: string): string {\n  if (!root || !isAbsolute(moduleId)) {\n    return moduleId\n  }\n  return relative(root, moduleId)\n}\n\nfunction normalizeBenchArgs(\n  a: BenchFn | BenchFnOptions,\n  b: BenchFn | BenchFnOptions | undefined,\n): { fn: BenchFn; fnOpts: BenchOptions | undefined; writeResult: string | undefined; perProject: boolean } {\n  if (typeof a === 'function') {\n    if (b !== undefined) {\n      throw new TypeError('`bench()` does not accept options as the third argument. Pass options as the second argument instead: `bench(name, options, fn)`.')\n    }\n    return { fn: a, fnOpts: undefined, writeResult: undefined, perProject: false }\n  }\n  if (typeof b !== 'function') {\n    throw new TypeError('`bench()` expects a benchmark function. Call `bench(name, fn)` or `bench(name, options, fn)`.')\n  }\n  // Strip vitest-specific fields only when present so we don't allocate a new\n  // object — preserving referential identity matters: users inspect\n  // `registration.fnOpts` and the provider sees the same object the caller\n  // passed in.\n  if (a.writeResult === undefined && a.perProject === undefined) {\n    return { fn: b, fnOpts: a as BenchOptions, writeResult: undefined, perProject: false }\n  }\n  const { writeResult, perProject, ...fnOpts } = a\n  return {\n    fn: b,\n    fnOpts: Object.keys(fnOpts).length > 0 ? fnOpts as BenchOptions : undefined,\n    writeResult,","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/benchmark.ts#L556-L592","documentation":"`bench(name, fn)` and `bench(name, options, fn)` are the only valid call shapes. There is no `bench(name, fn, options)` form. This `TypeError` fires when the second argument (`a`) is a function AND a third argument (`b`) is provided — Vitest infers the user put options in the wrong slot.","triggerScenarios":"Calling `bench('x', fn, { iterations: 100 })` — here `a = fn` (function) and `b = { iterations: 100 }` is defined, triggering the check at benchmark.ts:572-575. The valid form swaps the last two: `bench('x', { iterations: 100 }, fn)`.","commonSituations":"Muscle memory from `test(name, fn, timeout)` (Jest-style) where options/timeout come last; migrating from a library whose signature is `(name, fn, opts)`; autocomplete inserting options in the wrong position.","solutions":["Reorder to `bench(name, options, fn)`.","If you do not need options, call `bench(name, fn)` with two arguments only."],"exampleFix":"// before\nbench('sort', sortFn, { iterations: 100 })\n\n// after\nbench('sort', { iterations: 100 }, sortFn)","handlingStrategy":"validation","validationCode":"if (typeof a === 'function' && b !== undefined) throw new TypeError('move options to 2nd arg: bench(name, options, fn)')","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Memorize the two valid signatures: `bench(name, fn)` and `bench(name, options, fn)`.","Use TypeScript overloads — they enforce the order at compile time.","Run `pnpm lint` to catch argument-order mistakes early."],"tags":["benchmark","api-usage","argument-order"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}