Skip to main content
Module

x/scaffold/src/deps/types.ts>RequireAllOrNone

scaffold your next project with style and 💗
Latest
type alias RequireAllOrNone
import { type RequireAllOrNone } from "https://deno.land/x/scaffold@0.3.0/src/deps/types.ts";

Create a type that requires all of the given keys or none of the given keys. The remaining keys are kept as is.

Use-cases:

  • Creating interfaces for components with mutually-inclusive keys.

The caveat with RequireAllOrNone is that TypeScript doesn't always know at compile time every key that will exist at runtime. Therefore RequireAllOrNone can't do anything to prevent extra keys it doesn't know about.

Examples

Example 1

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

type Responder = {
	text?: () => string;
	json?: () => string;
	secure: boolean;
};

const responder1: RequireAllOrNone<Responder, 'text' | 'json'> = {
	secure: true
};

const responder2: RequireAllOrNone<Responder, 'text' | 'json'> = {
	text: () => '{"message": "hi"}',
	json: () => '{"message": "ok"}',
	secure: true
};

Type Parameters

ObjectType
optional
KeysType extends keyof ObjectType = never
definition: (Required<Pick<ObjectType, KeysType>> | Partial<Record<KeysType, never>>) & Omit<ObjectType, KeysType>