deep-partial
This package builds upon TypeScript's built-in Partial<T>
type by allowing deep
partials to be created.
The current behavior of TypeScript's Partial<T>
type means that nested objects
will not have the optional status applied to their fields. For example:
type Person = {
name: string;
age: number;
address: {
number: number;
street: string;
};
};
const myHouseNumber: Partial<Person> = { address: { number: 52 } };
// The above is invalid, and results in error: Property 'street' is missing in
// type '{ number: number; }' but required in type '{ number: number; street: string; }'.
Using DeepPartial<T>
instead makes this assignment possible:
const myHouseNumber: DeepPartial<Person> = { address: { number: 52 } };
Installation
Just a quick npm install --save-dev @tomysmith/deep-partial@latest
, or the Yarn
equivalent.