{"id":"7460784318d2ec98","repo":"sindresorhus/is","slug":"expected-value-which-is-truthy-received-value-o","errorCode":null,"errorMessage":"Expected value which is `truthy`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `truthy`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"warning","filePath":"source/index.ts","lineNumber":1908,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('SharedArrayBuffer', value));\n\t}\n}\n\nexport function assertString(value: unknown, message?: string): asserts value is string {\n\tif (!isString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('string', value));\n\t}\n}\n\nexport function assertSymbol(value: unknown, message?: string): asserts value is symbol {\n\tif (!isSymbol(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('symbol', value));\n\t}\n}\n\nexport function assertTruthy<T>(value: T | Falsy, message?: string): asserts value is T {\n\tif (!isTruthy(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('truthy', value));\n\t}\n}\n\nexport function assertTupleLike<T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T], message?: string): asserts value is ResolveTypesOfTypeGuardsTuple<T> {\n\tif (!isTupleLike(value, guards)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('tuple-like', value));\n\t}\n}\n\nexport function assertTypedArray(value: unknown, message?: string): asserts value is TypedArray {\n\tif (!isTypedArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('TypedArray', value));\n\t}\n}\n\nexport function assertUint16Array(value: unknown, message?: string): asserts value is Uint16Array {\n\tif (!isUint16Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint16Array', value));","sourceCodeStart":1890,"sourceCodeEnd":1926,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1890-L1926","documentation":"Thrown by `assert.truthy()` (assertTruthy at source/index.ts:1906) when the value is falsy: `false`, `0`, `-0`, `0n`, `''`, `null`, `undefined`, or `NaN`. Unlike the other assertions this is not a type check but a value check — its assertion signature narrows `T | Falsy` to `T`, which is why the codebase uses it to strip null/undefined/empty from union types.","triggerScenarios":"Calling `assert.truthy(value)` where value is `undefined` (missing property/return), `null` (API no-result), `0` or `''` — the last two are frequent false positives when zero or empty string are legitimate values.","commonSituations":"Using truthiness as a null-check on numeric fields where `0` is valid (counts, indexes, prices) or string fields where `''` is valid; lookup functions (`map.get`, `find`) returning `undefined`; NaN from failed numeric parsing sneaking through.","solutions":["If `0` or `''` are legitimate values, replace with a specific check: `assert.number(value)` plus an explicit `!== undefined` guard, rather than truthiness.","Trace why the value is `null`/`undefined` — a failed lookup or missing field — and handle that case explicitly before asserting.","Provide a domain-specific `message` argument so failures identify which value was falsy."],"exampleFix":"// before\nassert.truthy(items.indexOf(target)); // fails when index is 0!\n// after\nconst index = items.indexOf(target);\nassert.truthy(index !== -1, 'target not found in items');","handlingStrategy":"validation","validationCode":"if (!value) {\n  throw new TypeError(`Expected a truthy value, got ${value}`);\n}","typeGuard":"function isTruthy<T>(value: T): value is Exclude<T, false | 0 | 0n | '' | null | undefined> {\n  return Boolean(value);\n}","tryCatchPattern":"try {\n  assert.truthy(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // value was false, 0, -0, 0n, '', null, undefined, or NaN\n  }\n  throw error;\n}","preventionTips":["Know the full falsy list: false, 0, -0, 0n, '', null, undefined, NaN — legitimate values like 0 and '' fail this check","If 0 or empty string are valid inputs, use a null/undefined check (value != null) instead of a truthiness assertion","Set defaults with ?? rather than || so falsy-but-valid values survive"],"tags":["typescript","type-assertion","truthy","falsy","validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}