{"id":"ed0a0a0c48aafb68","repo":"sindresorhus/is","slug":"expected-value-which-is-not-description-rece","errorCode":null,"errorMessage":"Expected value which is not `${description}`, received value of type `${is(value)}`.","messagePattern":"Expected value which is not `(.+?)`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1171,"sourceCode":"type NotAssert = {\n\tundefined: NotAssertion<undefined, UnknownNotPrimitive<undefined>>;\n\t// eslint-disable-next-line @typescript-eslint/no-restricted-types\n\tnull: NotAssertion<null, UnknownNotPrimitive<null>>;\n\t// eslint-disable-next-line @typescript-eslint/no-restricted-types\n\tnullOrUndefined: NotAssertion<null | undefined, UnknownNotPrimitive<null | undefined>>;\n\tstring: NotAssertion<string, UnknownNotPrimitive<string>>;\n\tboolean: NotAssertion<boolean, UnknownNotPrimitive<boolean>>;\n\tsymbol: NotAssertion<symbol, UnknownNotPrimitive<symbol>>;\n\tbigint: NotAssertion<bigint, UnknownNotPrimitive<bigint>>;\n\t// eslint-disable-next-line @typescript-eslint/no-restricted-types\n\tprimitive: NotAssertion<Primitive, object>;\n};\n\n// Negative assertions are limited to types where the assertion rejects every TypeScript value assignable to the forbidden type. Structural object types such as `Map`, `Set`, `Date`, and `Array` are excluded because TypeScript accepts shape-compatible mocks while the runtime checks use object brands, so `Exclude` would narrow values that can pass the negative assertion.\nfunction createAssertNot<Forbidden, UnknownResult = unknown>(predicate: Predicate, description: AssertionTypeDescription): NotAssertion<Forbidden, UnknownResult> {\n\treturn <Value>(value: Value, message?: string): asserts value is NotAssertionResult<Value, Forbidden, UnknownResult> => {\n\t\tif (predicate(value)) {\n\t\t\tthrow new TypeError(message ?? typeErrorMessageNot(description, value));\n\t\t}\n\t};\n}\n\nexport const assertNotUndefined: NotAssertion<undefined, UnknownNotPrimitive<undefined>> = createAssertNot<undefined, UnknownNotPrimitive<undefined>>(isUndefined, 'undefined');\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport const assertNotNull: NotAssertion<null, UnknownNotPrimitive<null>> = createAssertNot<null, UnknownNotPrimitive<null>>(isNull, 'null');\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport const assertNotNullOrUndefined: NotAssertion<null | undefined, UnknownNotPrimitive<null | undefined>>\n\t// eslint-disable-next-line @typescript-eslint/no-restricted-types\n\t= createAssertNot<null | undefined, UnknownNotPrimitive<null | undefined>>(isNullOrUndefined, 'null or undefined');\nexport const assertNotString: NotAssertion<string, UnknownNotPrimitive<string>> = createAssertNot<string, UnknownNotPrimitive<string>>(isString, 'string');\nexport const assertNotBoolean: NotAssertion<boolean, UnknownNotPrimitive<boolean>> = createAssertNot<boolean, UnknownNotPrimitive<boolean>>(isBoolean, 'boolean');\nexport const assertNotSymbol: NotAssertion<symbol, UnknownNotPrimitive<symbol>> = createAssertNot<symbol, UnknownNotPrimitive<symbol>>(isSymbol, 'symbol');\nexport const assertNotBigint: NotAssertion<bigint, UnknownNotPrimitive<bigint>> = createAssertNot<bigint, UnknownNotPrimitive<bigint>>(isBigint, 'bigint');\nexport const assertNotPrimitive: NotAssertion<Primitive, object> = createAssertNot<Primitive, object>(isPrimitive, 'primitive'); // eslint-disable-line @typescript-eslint/no-restricted-types\n\n// We intentionally do not support `assert.not(is.undefined, value)`. TypeScript cannot derive safe complement types from arbitrary predicates, and many predicates here are refinements (for example, `is.number` rejects `NaN`). Explicit methods keep runtime checks and type narrowing aligned.","sourceCodeStart":1153,"sourceCodeEnd":1189,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1153-L1189","documentation":"Thrown by negative assertions created via `createAssertNot` (source/index.ts:1168) — e.g. `assertNotUndefined`, `assertNotNull`, `assertNotString` — when the value *does* match the forbidden type. The message from `typeErrorMessageNot` names the forbidden description and the actual detected type. This is the assertion working as designed: the value violated the 'must not be X' contract.","triggerScenarios":"Calling `assertNotUndefined(value)` when `value` is undefined, `assertNotNull(x)` when `x` is null, `assertNotString`/`assertNotBoolean`/`assertNotSymbol`/`assertNotBigint`/`assertNotPrimitive` when the value is of that exact forbidden type.","commonSituations":"Optional data (missing object property, unset env var, `Map.get` miss) flowing into a code path that asserts presence with `assertNotUndefined`/`assertNotNull`; API responses with null fields; race conditions where a value isn't initialized yet.","solutions":["Treat this as a data problem, not a library problem: trace why the value is the forbidden type at that point (missing config, absent field, uninitialized state) and fix the source.","If the forbidden type is legitimately possible, replace the assertion with a conditional branch that handles that case.","Pass a custom `message` argument to the assertion so failures identify which value and context failed."],"exampleFix":"// before\nconst url = process.env.API_URL;\nassertNotUndefined(url); // throws when env var unset\n\n// after\nconst url = process.env.API_URL;\nassertNotUndefined(url, 'API_URL environment variable must be set');","handlingStrategy":"try-catch","validationCode":"if (is.nan(value)) {\n  // handle the disallowed type yourself before calling assert.not.*\n}","typeGuard":"function isNot<T>(predicate: (v: unknown) => boolean, value: unknown): boolean {\n  return !predicate(value);\n}","tryCatchPattern":"try {\n  assert.not.undefined(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // value WAS of the disallowed type — report/reject at the boundary\n    return handleInvalidInput(error.message);\n  }\n  throw error;\n}","preventionTips":["Use the boolean predicate form (`is.x(value)`) to branch when a disallowed type is an expected runtime case; reserve `assert.*` for genuine invariants","Catch `TypeError` specifically at trust boundaries (API input, deserialization) and translate it into a user-facing validation error","Include the offending field name in your wrapper's error so the message's type description is actionable"],"tags":["assertion","runtime-check","null-safety"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}