PropertyTypeGuards<T>
One type guard per property of an object type, as objectTypeGuard takes them. Every key of T must be listed. The guard of an optional property is typed to narrow to undefined as well, but a guard that refuses undefined still compiles there, so widen it with optionalTypeGuard: an absent property reads as undefined, and a guard refusing it refuses the object.
Import:
import type { PropertyTypeGuards } from '@mnaoumov/typescript-lib/type-guards';Signature:
export type PropertyTypeGuards<T extends object>Signature:
type PropertyTypeGuards<T> = { readonly [TKey in keyof T]-?: TypeGuard<Partial<Pick<T, TKey>> extends Pick<T, TKey> ? T[TKey] | undefined : T[TKey]>;}Type: { readonly [TKey in keyof T]-?: TypeGuard<Partial<Pick<T, TKey>> extends Pick<T, TKey> ? T[TKey] | undefined : T[TKey]>; }
Links to this page: