react-querybuilder
Version:
React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts
27 lines (22 loc) • 686 B
text/typescript
import type { Except } from "./except.mjs";
/**
Create a type that requires at least one of the given keys. The remaining keys are kept as is.
@example
```
import type {RequireAtLeastOne} from 'type-fest';
type Responder = {
text?: () => string;
json?: () => string;
secure?: boolean;
};
const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
json: () => '{"message": "ok"}',
secure: true
};
```
@group type-fest
*/
export type RequireAtLeastOne<
ObjectType,
KeysType extends keyof ObjectType = keyof ObjectType
> = { [Key in KeysType]-? : Required<Pick<ObjectType, Key>> & Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] & Except<ObjectType, KeysType>;