import type {BuiltIns, HasMultipleCallSignatures} from './internal'; type ExcludeUndefined = Exclude; /** Create a type from another type with all keys and nested keys set to required. Use-cases: - Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified. - Modeling the resulting type after a deep merge with a set of defaults. @example ``` import type {RequiredDeep} from 'type-fest'; type Settings = { textEditor?: { fontSize?: number | undefined; fontColor?: string | undefined; fontWeight?: number | undefined; } autocomplete?: boolean | undefined; autosave?: boolean | undefined; }; type RequiredSettings = RequiredDeep; // type RequiredSettings = { // textEditor: { // fontSize: number; // fontColor: string; // fontWeight: number; // } // autocomplete: boolean; // autosave: boolean; // } ``` Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732). @category Utilities @category Object @category Array @category Set @category Map */ export type RequiredDeep = ExcludeUndefined> = E extends BuiltIns ? E : E extends Map ? Map, RequiredDeep> : E extends Set ? Set> : E extends ReadonlyMap ? ReadonlyMap, RequiredDeep> : E extends ReadonlySet ? ReadonlySet> : E extends WeakMap ? WeakMap, RequiredDeep> : E extends WeakSet ? WeakSet> : E extends Promise ? Promise> : E extends (...arguments_: any[]) => unknown ? {} extends RequiredObjectDeep ? E : HasMultipleCallSignatures extends true ? E : ((...arguments_: Parameters) => ReturnType) & RequiredObjectDeep : E extends object ? E extends Array // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156 ? ItemType[] extends E // Test for arrays (non-tuples) specifically ? Array> // Recreate relevant array type to prevent eager evaluation of circular reference : RequiredObjectDeep // Tuples behave properly : RequiredObjectDeep : unknown; type RequiredObjectDeep = { [KeyType in keyof ObjectType]-?: RequiredDeep };