Skip to main content

RequiredKeysOf<BaseType>

RequiredKeysOf<BaseType> = BaseType extends unknown ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never

Defined in: packages/react-querybuilder/src/types/type-fest/required-keys-of.ts:27

Extract all required keys from the given type.

This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...

Type Parameters

Type Parameter
BaseType extends object

Example

import type {RequiredKeysOf} from 'type-fest';

declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;

interface User {
name: string;
surname: string;

luckyNumber?: number;
}

const validator1 = createValidation<User>('name', value => value.length < 25);
const validator2 = createValidation<User>('surname', value => value.length < 25);

caution

API documentation is generated from the latest commit on the main branch. It may be somewhat inconsistent with official releases of React Query Builder.