{"id":"4040a0c43bba82fa","repo":"sindresorhus/is","slug":"expected-value-which-is-odd-integer-received-va","errorCode":null,"errorMessage":"Expected value which is `odd integer`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `odd integer`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1830,"sourceCode":"\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport function assertObject(value: unknown, message?: string): asserts value is object {\n\tif (!isObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Object', value));\n\t}\n}\n\nexport function assertObservable(value: unknown, message?: string): asserts value is ObservableLike {\n\tif (!isObservable(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Observable', value));\n\t}\n}\n\nexport function assertOddInteger(value: number, message?: string): asserts value is number {\n\tif (!isOddInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('odd integer', value));\n\t}\n}\n\nexport function assertPlainObject<Value = unknown>(value: unknown, message?: string): asserts value is Record<PropertyKey, Value> {\n\tif (!isPlainObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('plain object', value));\n\t}\n}\n\nexport function assertPositiveInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isPositiveInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('positive integer', value));\n\t}\n}\n\nexport function assertPositiveNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isPositiveNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('positive number', value));","sourceCodeStart":1812,"sourceCodeEnd":1848,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1812-L1848","documentation":"Thrown by `assert.oddInteger()` when the number is not an odd integer. Note the parameter is already typed `number` — this assert validates the runtime value's mathematical property (integer and odd), not just its type. Even integers, non-integer floats, NaN, and Infinity all fail.","triggerScenarios":"Calling `assert.oddInteger(value)` with an even integer (4), a float (3.5), NaN, Infinity, or the result of a division that didn't produce a whole number. Typical for parameters that must be odd, like kernel/window sizes or center-symmetric dimensions.","commonSituations":"Computing a window or kernel size from user input or image dimensions and getting an even result; off-by-one in loop math producing evens; parsing '3' correctly but then doubling it; NaN from a failed Number() conversion propagating in.","solutions":["Coerce to a valid odd integer before asserting, e.g. `const odd = 2 * Math.floor(n / 2) + 1`.","Check for NaN upstream — a failed parse silently produces NaN which fails here with a confusing 'number' received-type.","If odd is not a real requirement, use `assert.integer()` instead.","Validate user-facing inputs with a clear domain error ('window size must be odd') before this internal assert."],"exampleFix":"// before\nconst kernel = imageWidth / 10; // may be even or fractional\nassert.oddInteger(kernel);\n// after\nconst kernel = 2 * Math.floor(imageWidth / 20) + 1;\nassert.oddInteger(kernel);","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(value) || Math.abs(value % 2) !== 1) {\n  throw new TypeError(`Expected odd integer, got ${value}`);\n}","typeGuard":"function isOddInteger(value: unknown): value is number {\n  return typeof value === 'number' && Number.isInteger(value) && Math.abs(value % 2) === 1;\n}","tryCatchPattern":"try {\n  ow(value, ow.number.oddInteger);\n} catch (error) {\n  if (error instanceof ArgumentError) {\n    throw new RangeError(`Value must be an odd integer: ${error.message}`);\n  }\n  throw error;\n}","preventionTips":["Check Number.isInteger first — floats like 3.5 fail the odd check for a different reason than evens","Use Math.abs(n % 2) === 1 so negative odd numbers (-3 % 2 === -1) pass","If deriving from division, round explicitly (Math.floor/round) before the oddness check","For window/kernel-size parameters, document and enforce the odd requirement at your own API boundary"],"tags":["type-check","assertion","number-validation","integer"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}