Skip to content

Latest commit

History

History
22 lines (17 loc) 路 743 Bytes

README.md

File metadata and controls

22 lines (17 loc) 路 743 Bytes

Buildable<Type> constructs a type by combining DeepPartial and DeepWritable, meaning all properties from type Type are recursively set as non-readonly and optional, meaning they can be reassigned and aren't required

interface Company {
  readonly name: string;
  readonly employees: { readonly name: string }[];
}

type BuildableCompany = Buildable<Company>;
//   ^? { name?: string | undefined; employees?: ({ name?: string | undefined } | undefined)[] | undefined }

This allows building objects step-by-step by assigning property values in multiple statements:

declare const company: BuildableCompany;

company.name = "ts-essentials";
company.employees = [];
company.employees.push({ name: "Kris Kaczor" });