Skip to content

ObjectTypeGuardOptions<T>

Options for objectTypeGuard.

Import:

import type { ObjectTypeGuardOptions } from '@mnaoumov/typescript-lib/type-guards';

Signature:

export interface ObjectTypeGuardOptions<T extends object = object>

Properties

PropertyTypeDescription
exactOptionalKeys?Readonly<Record<OptionalKeys<T>, true>>Switches the guard to EXACT optional properties, reading only the value's OWN keys. Listing it is the switch, so pass {} for a type with no optional key.

Every optional key of T must be listed, so an optional property later added to T fails to compile until it is. A listed key may then be absent, and its guard is not run; present, even as undefined, it must pass its guard. Any other key must be present. An inherited key counts as absent.

Without it, a property is read with Reflect.get, so an inherited one counts and an absent one reads as undefined, which the guard of an optional property must then accept.
shouldRejectUnknownKeys?booleanWhether a value carrying an own enumerable string key that no property guard names is refused.

Links to this page: