/** * @file * * Contains utility functions for type guards. */ /** * A generic object with `string` keys and `unknown` values. * * Used as a widening target for dynamic property access on mock objects. */ export type GenericObject = Record; type NullableConstraint = null extends T ? unknown : undefined extends T ? unknown : never; /** * Asserts that a branch is unreachable, so an unhandled `switch` case becomes a compile error. * * @param value - The value whose type must have been narrowed to `never` by the preceding branches. * @throws Always, naming the value that reached the branch at runtime. */ export declare function assertNever(value: never): never; /** * Asserts that a value is not `null` or `undefined`, narrowing its type in place. * * Only callable when `T` includes `null` or `undefined`. Passing an already non-nullable type is a compile error. * * @typeParam T - The type of the value. * @param value - The value to check. * @param errorOrMessage - Optional {@link Error} or error message string. * @throws If the value is `null` or `undefined`. */ export declare function assertNonNullable>(value: T, errorOrMessage?: Error | string): asserts value is NonNullable; /** * Casts a value to a specific type without any runtime check. * * Prefer this over inline `as` assertions: it keeps the unsafe cast in one * auditable place and reads as an explicit, intentional escape hatch. * * @typeParam T - The target type to cast to. * @param value - The value to cast. * @returns The value typed as `T`. */ export declare function castTo(value: unknown): T; /** * Widens an object to a {@link GenericObject} so dynamic string-keyed property * access type-checks. * * @typeParam T - The object type. * @param object - The object to widen. * @returns The same object typed as `GenericObject & T`. */ export declare function ensureGenericObject(object: T): GenericObject & T; /** * Ensures that a value is not `null` or `undefined` and returns it with narrowed type. * * Only callable when `T` includes `null` or `undefined`. Passing an already non-nullable type is a compile error. * * @typeParam T - The type of the value. * @param value - The value to check. * @param errorOrMessage - Optional {@link Error} or error message string. * @returns The value with `null` and `undefined` excluded from its type. * @throws If the value is `null` or `undefined`. */ export declare function ensureNonNullable>(value: T, errorOrMessage?: Error | string): NonNullable; export {};