Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 817 Bytes

File metadata and controls

57 lines (40 loc) · 817 Bytes

typelab / utils / ObjectWritable

type ObjectWritable<T, K> = IsObjectLiteral<T> extends true ? Detailed<{ -readonly [Key in K]: T[K] } & { [Key in keyof T as Key extends K ? never : Key]: T[Key] }> : never;

Enforce specific properties as writable.

Type Parameters

Type Parameter Description

T

The original object type.

K extends keyof T

The keys of T that should be writable.

Returns

A type with the specified keys of T set as writable.

Example

type Obj = { readonly a: string; b: string };

// WritableObj is { a: string; b: string; }
type WritableObj = ObjectWritable<Obj, 'a'>;