@tomysmith/deep-partial
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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.

Package Sidebar

Install

npm i @tomysmith/deep-partial

Weekly Downloads

27

Version

1.0.1

License

ISC

Unpacked Size

1.93 kB

Total Files

5

Last publish

Collaborators

  • tomysmith