Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 629 Bytes

README.md

File metadata and controls

24 lines (18 loc) · 629 Bytes

DeepWritable<Type> constructs a type by picking all properties from type Type recursively and removing readonly modifier, meaning they can be reassigned.

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

type DeepWritableCompany = DeepWritable<Company>;
//   ^? { name: string; employees: {name: string}[]}

Useful when object needs to be mutable, e.g. in tests

declare const company: DeepWritableCompany;

company.name = "ts-essentials";
company.employees = [];
company.employees[0].name = "Kris Kaczor";

TS Playground – https://tsplay.dev/N75yoW