UNPKG

guardz

Version:

A simple and lightweight TypeScript type guard library for runtime type validation.

38 lines (37 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isObjectWith = isObjectWith; const isType_1 = require("./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 * } * ``` */ function isObjectWith(propsTypesToCheck) { return (0, isType_1.isType)(propsTypesToCheck); }