import { type PartialOnUndefinedDeep } from "https://deno.land/x/actionify@0.3.0/src/deps/types.ts";
Create a deep version of another type where all keys accepting undefined
type are set to optional.
This utility type is recursive, transforming at any level deep. By default, it does not affect arrays and tuples items unless you explicitly pass {recurseIntoArrays: true}
as the second type argument.
Use-cases:
- Make all properties of a type that can be undefined optional to not have to specify keys with undefined value.
Examples
Example 1
Example 1
import type {PartialOnUndefinedDeep} from 'type-fest';
interface Settings {
optionA: string;
optionB: number | undefined;
subOption: {
subOptionA: boolean;
subOptionB: boolean | undefined;
}
};
const testSettings: PartialOnUndefinedDeep<Settings> = {
optionA: 'foo',
// 👉 optionB is now optional and can be omitted
subOption: {
subOptionA: true,
// 👉 subOptionB is now optional as well and can be omitted
},
};
Type Parameters
optional
Options extends PartialOnUndefinedDeepOptions = { }definition: T extends Record<any, any> | undefined ? [KeyType in keyof Tin keyof undefined extends T[KeyType] ? KeyType : never]?: PartialOnUndefinedDeepValue<T[KeyType], Options> extends infer U ? Merge<[KeyType in keyof Tin keyof KeyType extends keyof U ? never : KeyType]: PartialOnUndefinedDeepValue<T[KeyType], Options>, U> : never : T