Skip to content

ObjectGuardOptions<T>

Options for objectGuard.

Import:

import type { ObjectGuardOptions } from '@mnaoumov/typescript-lib/api-contract';

Signature:

export interface ObjectGuardOptions<T extends object> extends ObjectTypeGuardOptions<T>

Extends: ObjectTypeGuardOptions<T>

Properties

PropertyTypeDescription
description?stringWhat the object is, put before its properties in expected, e.g. 'the options of the link'.
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.
(Inherited from ObjectTypeGuardOptions)
shouldRejectUnknownKeys?booleanWhether a value carrying an own enumerable string key that no property guard names is refused.
(Inherited from ObjectTypeGuardOptions)

Links to this page: