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:

    const x: 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

  // 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
const validateStateChange = TestValidator.notEquals("state should have changed");
validateStateChange(initialState)(currentState);

// Type-safe nullable comparisons
const mutableData: { count: number } | null = getMutableData();
TestValidator.notEquals("should have changed")(mutableData)(null); // ✅ Safe

Error when values are equal (indicating validation failure)

  • Parameters

    • title: string

      Descriptive title used in error messages when values are equal

    • exception: (key: string) => boolean = ...

      Optional filter function to exclude specific keys from comparison

    Returns <T>(actual: T) => (expected: undefined | null | T) => void

    A currying function chain: first accepts expected value, then actual value