Sha256: 55a84db1ca921c86709117fabae152ab802511dd395c26d6049e6d4fb1e78112

Contents?: true

Size: 848 Bytes

Versions: 61

Compression:

Stored size: 848 Bytes

Contents

import {Except} from './except';

/**
Create a type that requires at least one of the given keys. The remaining keys are kept as is.

@example
```
import {RequireAtLeastOne} from 'type-fest';

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

	secure?: boolean;
};

const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
	json: () => '{"message": "ok"}',
	secure: true
};
```
*/
export type RequireAtLeastOne<
	ObjectType,
	KeysType extends keyof ObjectType = keyof ObjectType
> = {
	// For each `Key` in `KeysType` make a mapped type:
	[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & // 1. Make `Key`'s type required
		// 2. Make all other keys in `KeysType` optional
		Partial<Pick<ObjectType, Exclude<KeysType, Key>>>;
}[KeysType] &
	// 3. Add the remaining keys not in `KeysType`
	Except<ObjectType, KeysType>;

Version data entries

61 entries across 61 versions & 4 rubygems

Version Path
immosquare-cleaner-0.1.18 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.17 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.16 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.14 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.13 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.12 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.11 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.10 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.9 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.8 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.7 node_modules/type-fest/source/require-at-least-one.d.ts
immosquare-cleaner-0.1.6 node_modules/type-fest/source/require-at-least-one.d.ts
decidim-0.26.8 packages/eslint-config/node_modules/type-fest/source/require-at-least-one.d.ts
reed_sdk-1.0.1 node_modules/type-fest/source/require-at-least-one.d.ts
reed_sdk-1.0.0 node_modules/type-fest/source/require-at-least-one.d.ts
decidim-0.27.1 packages/webpacker/node_modules/type-fest/source/require-at-least-one.d.ts
decidim-0.26.4 packages/webpacker/node_modules/type-fest/source/require-at-least-one.d.ts
decidim-0.27.0 packages/webpacker/node_modules/type-fest/source/require-at-least-one.d.ts
decidim-0.26.3 packages/webpacker/node_modules/type-fest/source/require-at-least-one.d.ts
decidim-0.27.0.rc2 packages/webpacker/node_modules/type-fest/source/require-at-least-one.d.ts