-
-
Notifications
You must be signed in to change notification settings - Fork 0
type assertion
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
export type Assertion<
Type extends Base = any,
Base = unknown,
Args extends readonly unknown[] = readonly any[],
> = Expand<(it: Base, ...args: Args) => asserts it is Type>;Represents an assertion function that checks if a given value of the base type
Base is also of the derived type Type. If the value is not of the derived
type, it will throw an error.
-
TypeextendsBase(default:any) -
Base(default:unknown) -
Argsextendsreadonly unknown[](default:readonly any[])
const assertString: Assertion<string> = (it: unknown): asserts it is string => {
if (typeof it !== "string") {
throw new TypeError("Expected a string");
}
};