Validates deep inequality between two values using JSON comparison.
Performs recursive comparison of objects and arrays to ensure they are NOT
equal. Supports an optional exception filter to ignore specific keys during
comparison. Useful for validating that data has changed, objects are
different, or mutations have occurred.
Type Safety Notes:
The generic type T is inferred from the actual parameter (first in the
currying chain)
The expected parameter must be assignable to T | null | undefined
For objects, expected must have the same or subset of properties as
actual
For union types like string | null, ensure proper type compatibility:
constx: string | null; TestValidator.notEquals("works")(x)(null); // ✅ Works: null is assignable to string | null TestValidator.notEquals("error")(null)(x); // ❌ Error: x might be string, but expected is null
Example
// Basic inequality TestValidator.notEquals("user should be different after update")(originalUser)(updatedUser);
// Ignore timestamps in comparison TestValidator.notEquals("user data should differ", (key) =>key === "updatedAt")( originalUser )(modifiedUser);
// Validate state changes constvalidateStateChange = TestValidator.notEquals("state should have changed"); validateStateChange(initialState)(currentState);
// Type-safe nullable comparisons constmutableData: { count: number } | null = getMutableData(); TestValidator.notEquals("should have changed")(mutableData)(null); // ✅ Safe
Throws
Error when values are equal (indicating validation failure)
Validates deep inequality between two values using JSON comparison.
Performs recursive comparison of objects and arrays to ensure they are NOT equal. Supports an optional exception filter to ignore specific keys during comparison. Useful for validating that data has changed, objects are different, or mutations have occurred.
Type Safety Notes:
The generic type T is inferred from the
actual
parameter (first in the currying chain)The
expected
parameter must be assignable toT | null | undefined
For objects,
expected
must have the same or subset of properties asactual
For union types like
string | null
, ensure proper type compatibility:Example
Throws
Error when values are equal (indicating validation failure)