{"record":{"id":"dd8f04425333caf3","repo":"avajs/ava","slug":"the-any-property-of-the-second-argument-to-as","errorCode":null,"errorMessage":"The `any` property of the second argument to `${assertion}` must be a boolean","messagePattern":"The `any` property of the second argument to `(.+?)` must be a boolean","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":132,"sourceCode":"\t\t\t});\n\t\t}\n\n\t\tif (Object.hasOwn(expectations, 'name') && typeof expectations.name !== 'string') {\n\t\t\tthrow new AssertionError(`The \\`name\\` property of the second argument to \\`${assertion}\\` must be a string`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tif (Object.hasOwn(expectations, 'code') && typeof expectations.code !== 'string' && typeof expectations.code !== 'number') {\n\t\t\tthrow new AssertionError(`The \\`code\\` property of the second argument to \\`${assertion}\\` must be a string or number`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tif (Object.hasOwn(expectations, 'any') && typeof expectations.any !== 'boolean') {\n\t\t\tthrow new AssertionError(`The \\`any\\` property of the second argument to \\`${assertion}\\` must be a boolean`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tfor (const key of Object.keys(expectations)) {\n\t\t\tswitch (key) {\n\t\t\t\tcase 'instanceOf':\n\t\t\t\tcase 'is':\n\t\t\t\tcase 'message':\n\t\t\t\tcase 'name':\n\t\t\t\tcase 'code':\n\t\t\t\tcase 'any': {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new AssertionError(`The second argument to \\`${assertion}\\` contains unexpected properties`, {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L114-L150","documentation":"Thrown by validateExpectations in lib/assert.js:132 when an expectation object passed as the second argument to a throws assertion (e.g. t.throws / t.throwsAsync in AVA) has an `any` property whose value is not a boolean. The `any: true` option opt-in allows the assertion to accept thrown values that are not native Error instances. This is an improper-usage error: the assertion can never run, so the library fails fast with an AssertionError instead.","triggerScenarios":"Calling t.throws(fn, {any: 1}), t.throws(fn, {any: 'true'}), or t.throwsAsync(promise, {any: null}) — i.e. `Object.hasOwn(expectations, 'any')` is true but `typeof expectations.any !== 'boolean'`.","commonSituations":"Typing `any: 'true'` or `any: 1` by hand; building the expectations object dynamically from config/CLI flags where a string 'true' isn't converted; TypeScript users bypassing types with `as any`; copying examples of older APIs where truthiness was tolerated.","solutions":["Change the value of `any` to a real boolean: `t.throws(fn, {any: true})` or omit the property entirely.","If the value comes from user input or config, coerce it explicitly: `any: Boolean(cfgValue)` or `any: cfgValue === 'true'`.","If you meant 'accept any thrown value' without the non-error relaxation, remove `any` and use other keys like `is`, `name`, or `message`."],"exampleFix":"// before\nt.throws(() => parse(raw), { any: 'true' });\n\n// after\nt.throws(() => parse(raw), { any: true });","handlingStrategy":"validation","validationCode":"function assertValidExpectations(expectations) {\n  if (expectations && Object.hasOwn(expectations, 'any') && typeof expectations.any !== 'boolean') {\n    throw new TypeError('expectations.any must be a boolean');\n  }\n}","typeGuard":"function hasValidAny(e) {\n  return e == null || !('any' in e) || typeof e.any === 'boolean';\n}","tryCatchPattern":"try {\n  t.throws(fn, {any: true});\n} catch (error) {\n  if (error.name === 'AssertionError' && /must be a boolean/.test(error.message)) {\n    // fix expectations object before re-running\n  }\n  throw error;\n}","preventionTips":["Only ever write the literals `any: true` or `any: false` in expectations.","Coerce dynamic config values with Boolean() or === 'true' before assigning `any`.","Enable TypeScript/strict typing on the expectations object so non-booleans are caught at compile time."],"tags":["assertion","improper-usage","type-mismatch","ava"],"backgroundTag":"invalid-assertion-options","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}