Skip to content

Latest commit

 

History

History

deep-writable

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

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