assert
AssertTrue and AssertFalse — the assertion primitives.
import type { AssertTrue, AssertFalse } from '@gentleduck/ttest/assert'
Two thin assertion types that surface a string message at the point of failure. The predicate goes in the first generic; a human-readable message goes in the second. When the predicate fails its constraint, the compiler reports the assertion line with the message visible in the diagnostic. Pair with Equal, NotEqual, or any boolean utility.
AssertTrue
type AssertTrue<T extends true, Msg extends string> = T extends true ? true : never & Msg
Asserts that T is true. On failure the compiler emits TS2344: Type 'false' does not satisfy the constraint 'true' on the assertion line.
import type { Equal } from '@gentleduck/ttest/equality'
type pass = AssertTrue<Equal<1, 1>, '1 equals 1'>
type fail = AssertTrue<Equal<1, 2>, '1 does not equal 2'>
// ^ TS2344: Type 'false' does not satisfy the constraint 'true'.
// Compose multiple checks into a tuple. The compiler reports the failing index.
type _ = [
AssertTrue<Equal<1, 1>, 'one equals one'>,
AssertTrue<Equal<{ a: 1 }, { a: 1 }>, 'shape equality'>,
]
Edge cases:
- The constraint is
extends true, notextends boolean.AssertTrue<boolean, ...>fails becausebooleanistrue | false. anysatisfiesextends true— guard public types withIsAnybefore asserting.
AssertFalse
type AssertFalse<T extends false, Msg extends string> = T extends false ? true : never & Msg
Negative-polarity twin of AssertTrue. Use when negation is the natural reading rather than wrapping in Not<...>.
import type { Equal } from '@gentleduck/ttest/equality'
type pass = AssertFalse<Equal<1, 2>, '1 must not equal 2'>
type fail = AssertFalse<Equal<1, 1>, '1 must not equal 2'>
// ^ TS2344: Type 'true' does not satisfy the constraint 'false'.
import type { IsAny } from '@gentleduck/ttest/any'
// Lock public types against any leaks.
type _no_leak = AssertFalse<IsAny<User['id']>, 'User.id must not be any'>
Edge cases:
AssertFalse<boolean, ...>fails —booleanis not exactlyfalse.AssertFalse<never, ...>passes becausenever extends falseholds vacuously. PreferIsNeverwhenneveris the actual target.
For the broader assertion workflow see Core / Assertions.