forked from hpi-sam/digital-fuesim-manv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
immutability.ts
30 lines (28 loc) · 947 Bytes
/
immutability.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// TODO: Add typings for JsonObjects
/**
* An immutable object is an object whose state cannot be modified.
* Makes all properties in the given object readonly (recursive).
*
* The provided object should be a JSON object (no Maps, Sets, Functions, ...).
*/
export type Immutable<T extends object> = {
readonly [K in keyof T]: T[K] extends object ? Immutable<T[K]> : T[K];
};
/**
* A mutable object is an object whose state can be modified.
* Removes all readonly modifiers from the given object (recursive).
*
* The provided object should be a JSON object (no Maps, Sets, Functions, ...).
*
* If a union of types is provided, all objects in the union will be made mutable.
*/
export type Mutable<T> = {
-readonly [K in keyof T]: Mutable<T[K]>;
};
/**
* This represents a union of all JSON objects (no Maps, Sets, Functions, ...).
* TODO: the type doesn't work yet.
*/
export interface JsonObject {
[x: string]: any;
}