1 import {Except} from './except';
4 Create a type that requires at least one of the given keys. The remaining keys are kept as is.
8 import {RequireAtLeastOne} from 'type-fest';
17 const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
18 json: () => '{"message": "ok"}',
23 export type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
25 // For each Key in KeysType make a mapped type
27 // …by picking that Key's type and making it required
28 Required<Pick<ObjectType, Key>>
31 // …then, make intersection types by adding the remaining keys to each mapped type.
32 & Except<ObjectType, KeysType>;