Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/actionify/src/deps/types.ts>PartialDeep

Create and manage your GitHub workflows with TypeScript and Deno.
Latest
type alias PartialDeep
import { type PartialDeep } from "https://deno.land/x/actionify@0.3.0/src/deps/types.ts";

Create a type from another type with all keys and nested keys set to optional.

Use-cases:

  • Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
  • Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.

Examples

Example 1

import type {PartialDeep} from 'type-fest';

const settings: Settings = {
	textEditor: {
		fontSize: 14;
		fontColor: '#000000';
		fontWeight: 400;
	}
	autocomplete: false;
	autosave: true;
};

const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
	return {...settings, ...savedSettings};
}

settings = applySavedSettings({textEditor: {fontWeight: 500}});

By default, this also affects array and tuple types:

import type {PartialDeep} from 'type-fest';

interface Settings {
	languages: string[];
}

const partialSettings: PartialDeep<Settings> = {
	languages: [undefined]
};

If this is undesirable, you can pass {recurseIntoArrays: false} as the second type argument.

Type Parameters

T
optional
Options extends PartialDeepOptions = { }
definition: T extends BuiltIns ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType, Options> : T extends Set<infer ItemType> ? PartialSetDeep<ItemType, Options> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType, Options> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType, Options> : T extends ((...arguments: any[]) => unknown) ? T | undefined : T extends object ? T extends ReadonlyArray<infer ItemType> ? Options["recurseIntoArrays"] extends false ? T : ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<PartialDeep<ItemType | undefined, Options>> : Array<PartialDeep<ItemType | undefined, Options>> : PartialObjectDeep<T, Options> : PartialObjectDeep<T, Options> : unknown