The first type for comparison. Can be any TypeScript type including:
The second type for comparison. Same constraints as type A.
A string literal representing the expected type
relationship. TypeScript's type system automatically infers and restricts
the available operators based on the actual relationship between types A
and B. If an invalid relationship is specified, TypeScript will show a
compilation error.
Combine expectType with runtime assertions for comprehensive testing:
A and B..test.mts files alongside runtime
assertions.
Compile-time type assertion utility for TypeScript type testing.
This function performs static type relationship checking at compile-time and has no runtime effect. It is primarily used in test files to verify that TypeScript's type inference and type relationships work as expected. The function will cause TypeScript compilation errors if the specified type relationship does not hold.
Supported Type Relations
Equality Relations
"="(strict equality): Asserts that typesAandBare exactly the same type. Uses TypeScript's internal type equality checking."!="(strict inequality): Asserts that typesAandBare not exactly the same type.Assignability Relations
"~="(mutual assignability): Asserts thatAextendsBANDBextendsA. Types are structurally equivalent and mutually assignable."<="(subtype relation): Asserts that typeAextends (is assignable to) typeB. TypeAis a subtype ofB.">="(supertype relation): Asserts that typeBextends (is assignable to) typeA. TypeAis a supertype ofB.Negative Assignability Relations
"!<="(not subtype): Asserts that typeAdoes NOT extend typeB."!>="(not supertype): Asserts that typeBdoes NOT extend typeA.Type Parameter Constraints