The first type to compare
The second type to compare
Basic type equality:
type Test1 = Equal<string, string>; // true
type Test2 = Equal<string, number>; // false
type Test3 = Equal<string, any>; // false
type Test4 = Equal<unknown, any>; // false
Structural equality:
type User = { name: string; age: number };
type Person = { name: string; age: number };
type Employee = { name: string; age: number; role: string };
type Test1 = Equal<User, Person>; // true (same structure)
type Test2 = Equal<User, Employee>; // false (different structure)
Union type equality:
type Test1 = Equal<1 | 2 | 3, 3 | 2 | 1>; // true (order doesn't matter)
type Test2 = Equal<true | false, boolean>; // true (equivalent)
type Test3 = Equal<string | number, any>; // false (any is not a union)
Use with Assert for compile-time type checking:
import { Assert, type Check } from "typesafe-ts/assert";
type ApiResponse = { data: string };
type ExpectedShape = { data: string };
// ✅ Passes - types are equal
Assert<Check.Equal<ApiResponse, ExpectedShape>, "API response shape mismatch">();
// ❌ Fails - types are different
Assert<Check.Equal<ApiResponse, { data: number }>, "Wrong data type">();
Utility type to check if two types are exactly equal.
This performs a strict equality check that distinguishes between
any,unknown,never, and other types that might seem similar but are actually different.