{"id":"638d76e7de499b99","repo":"sindresorhus/is","slug":"expected-value-which-is-boolean-received-value","errorCode":null,"errorMessage":"Expected value which is `boolean`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `boolean`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1510,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('BigInt64Array', value));\n\t}\n}\n\nexport function assertBigUint64Array(value: unknown, message?: string): asserts value is BigUint64Array {\n\tif (!isBigUint64Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('BigUint64Array', value));\n\t}\n}\n\nexport function assertBlob(value: unknown, message?: string): asserts value is Blob {\n\tif (!isBlob(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Blob', value));\n\t}\n}\n\nexport function assertBoolean(value: unknown, message?: string): asserts value is boolean {\n\tif (!isBoolean(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('boolean', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertBoundFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isBoundFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('bound Function', value));\n\t}\n}\n\n/**\nNote: [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)\n*/\nexport function assertBuffer(value: unknown, message?: string): asserts value is NodeBuffer {\n\tif (!isBuffer(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Buffer', value));\n\t}\n}","sourceCodeStart":1492,"sourceCodeEnd":1528,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1492-L1528","documentation":"Thrown by `assertBoolean()` when the value is not a primitive `true`/`false` per `isBoolean` (typeof check; Boolean objects don't count in strict primitive terms). Ensures code branching on the value gets a genuine boolean rather than a truthy/falsy stand-in.","triggerScenarios":"Calling `assert.boolean(value)` with the strings 'true'/'false', 0/1, undefined, null, or a `new Boolean(...)` wrapper object.","commonSituations":"Environment variables and query-string parameters are always strings ('true' !== true); JSON configs hand-edited with quoted booleans; database drivers returning 0/1 tinyint for boolean columns; optional flags left undefined instead of defaulted.","solutions":["Coerce string flags explicitly before asserting: `value === 'true'` for env vars/query params.","Default optional flags: `assert.boolean(options.flag ?? false)` or validate presence separately.","Fix the config source to use unquoted JSON booleans.","For DB values, map 0/1 to Boolean at the data-access layer."],"exampleFix":"// before\nassert.boolean(process.env.DEBUG);\n// after\nassert.boolean(process.env.DEBUG === 'true');","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'boolean') {\n  // coerce deliberately: value = value === 'true' — never rely on truthiness\n}","typeGuard":"function isBoolean(value: unknown): value is boolean {\n  return typeof value === 'boolean';\n}","tryCatchPattern":"try {\n  assert.boolean(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // strings 'true'/'false', 0/1, or undefined slipped through — coerce explicitly at the boundary\n  } else throw error;\n}","preventionTips":["Environment variables and query params are always strings — parse 'true'/'false' explicitly before passing them on","Avoid Boolean object wrappers (new Boolean(true)); they fail typeof checks","Give optional boolean parameters explicit defaults (flag = false) so undefined never reaches the assertion"],"tags":["type-assertion","boolean","config","coercion"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}