API reference › @evolu/common › Assert › assertSame
const assertSame: <Expected>(
actual: unknown,
expected: Expected,
) => asserts actual is Expected;
Defined in: packages/common/src/Assert.ts:1009
Asserts that two values are the same using Object.is.
Use this when exact sameness is the contract, such as asserting reference identity or narrowing the actual value to the expected value's type, as shown below. For value comparisons, use assertEqual.
Uses the same equality semantics as assert.strictEqual from
node:assert/strict, but is platform-agnostic. See eqSameValue for
the equality semantics.
Example
import { assertSame, assertType } from "@evolu/common";
interface User {
readonly name: string;
}
const user: User = { name: "Ada" };
const value: unknown = user;
assertSame(value, user);
// `assertSame` narrows `value` from `unknown` to `User`.
assertType<typeof value, User>();