import type {IsAny} from './is-any.d.ts'; import type {NonRecursiveType, StringToNumber} from './internal/index.d.ts'; import type {Paths} from './paths.d.ts'; import type {SetRequired} from './set-required.d.ts'; import type {SimplifyDeep} from './simplify-deep.d.ts'; import type {UnionToTuple} from './union-to-tuple.d.ts'; import type {RequiredDeep} from './required-deep.d.ts'; import type {UnknownArray} from './unknown-array.d.ts'; /** Create a type that makes the given keys required. You can specify deeply nested key paths. The remaining keys are kept as is. Use-case: Selectively make nested properties required in complex types like models. @example ``` import type {SetRequiredDeep} from 'type-fest'; type Foo = { a?: number; b?: string; c?: { d?: number }[] } type SomeRequiredDeep = SetRequiredDeep; //=> { // a: number; // Is now required // b?: string; // c?: { // d: number; // Is now required // }[]; // } // Set specific indices in an array to be required. type ArrayExample = SetRequiredDeep<{a: [number?, number?, number?]}, 'a.0' | 'a.1'>; //=> {a: [number, number, number?]} ``` @category Object */ export type SetRequiredDeep> = IsAny extends true ? SimplifyDeep> : SetRequiredDeepHelper>; /** Internal helper for {@link SetRequiredDeep}. Recursively transforms the `BaseType` by applying {@link SetRequiredDeepSinglePath} for each path in `KeyPathsTuple`. */ type SetRequiredDeepHelper = KeyPathsTuple extends [infer KeyPath, ...infer RestPaths] ? SetRequiredDeepHelper, RestPaths> : BaseType; /** Makes a single path required in `BaseType`. */ type SetRequiredDeepSinglePath = BaseType extends NonRecursiveType ? BaseType : KeyPath extends `${infer Property}.${infer RestPath}` ? { [Key in keyof BaseType]: Property extends `${Key & (string | number)}` ? SetRequiredDeepSinglePath : BaseType[Key]; } : SetRequired) & keyof BaseType>; export {};