Sha256: f2d1ac34b05bb6ce326ea1702befb0216363f1d5eccdd1b4b0b2f5a7e953ed8a

Contents?: true

Size: 1.16 KB

Versions: 24

Compression:

Stored size: 1.16 KB

Contents

import {RequiredKeysOf} from './required-keys-of';

/**
Creates a type that represents `true` or `false` depending on whether the given type has any required fields.

This is useful when you want to create an API whose behavior depends on the presence or absence of required fields.

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

type GeneratorOptions<Template extends object> = {
	prop1: number;
	prop2: string;
} & (HasRequiredKeys<Template> extends true
	? {template: Template}
	: {template?: Template});

interface Template1 {
	optionalSubParam?: string;
}

interface Template2 {
	requiredSubParam: string;
}

type Options1 = GeneratorOptions<Template1>;
type Options2 = GeneratorOptions<Template2>;

const optA: Options1 = {
	prop1: 0,
	prop2: 'hi'
};
const optB: Options1 = {
	prop1: 0,
	prop2: 'hi',
	template: {}
};
const optC: Options1 = {
	prop1: 0,
	prop2: 'hi',
	template: {
		optionalSubParam: 'optional value'
	}
};

const optD: Options2 = {
	prop1: 0,
	prop2: 'hi',
	template: {
		requiredSubParam: 'required value'
	}
};

```

@category Utilities
*/
export type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.50 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.49 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.48 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.47 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.46 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.45 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.44 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.43 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.42 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.41 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.40 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.39 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.38 node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.32 node_modules/boxen/node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.31 node_modules/boxen/node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.30 node_modules/boxen/node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.29 node_modules/boxen/node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.28 node_modules/boxen/node_modules/type-fest/source/has-required-keys.d.ts
immosquare-cleaner-0.1.27 node_modules/boxen/node_modules/type-fest/source/has-required-keys.d.ts