guardz
Version:
A simple and lightweight TypeScript type guard library for runtime type validation.
36 lines (35 loc) • 1.08 kB
TypeScript
import { type TypeGuardFn, type TypeGuardFnConfig } from './isType';
/**
* Alias for isType - creates a type guard function for a specific object shape.
*
* This function is an alias for isType and provides a more descriptive name
* for creating type guards that validate object structures with specific properties.
*
* @param propsTypesToCheck - Object mapping property keys to their type guard functions
* @returns A type guard function that validates the object structure
*
* @example
* ```typescript
* interface User {
* id: number;
* name: string;
* email: string;
* }
*
* const isUser = isObjectWith<User>({
* id: isNumber,
* name: isString,
* email: isString,
* });
*
* const user = { id: 1, name: 'John', email: 'john@example.com' };
* if (isUser(user)) {
* // user is now typed as User
* console.log(user.name); // TypeScript knows this is a string
* }
* ```
*/
export declare function isObjectWith<T>(propsTypesToCheck: {
[P in keyof T]: TypeGuardFn<T[P]>;
}): TypeGuardFn<T>;
export type { TypeGuardFn, TypeGuardFnConfig };