Skip to content

Commit

Permalink
feat(type-helper): Add Mutable and Immutable types
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jan 15, 2024
1 parent 0e3d56f commit bd57df7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/type-helper/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ export type OptionalKeys<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? K : never;
}[keyof T];

/**
* Represents a type that makes all properties of an object mutable (remove readonly).
*/
export type Mutable<T> = {
-readonly [P in keyof T]: T[P];
};

/**
* Represents a type that makes all properties of an object immutable (readonly).
*/
export type Immutable<T> = {
readonly [P in keyof T]: T[P];
}

/**
* Represents a type that makes all properties of an object and its nested objects readonly.
* @template T - The type to make readonly.
Expand Down

0 comments on commit bd57df7

Please sign in to comment.