🧰 Essentials | Types - traced-fabric/core GitHub Wiki
All exported JSON types.
type JSONPrimitive = string | number | boolean | null | undefined;
type JSONObject = { [_key: string]: JSONValue };
type JSONArray = Array<JSONValue>;
type JSONStructure = JSONObject | JSONArray;
type JSONValue = JSONPrimitive | JSONStructure;
The definition of the mutation includes:
- targetChain (array of TTarget) - the path to the mutated property.
type TTarget = string | number;
// that is then used as targetChain: TTarget[];
- mutated - the JSONStructure that was mutated (array | object)
export enum EMutated {
object = 'object',
array = 'array',
}
- type - the type of mutation that happened. Different for object and array types.
export enum EObjectMutation {
set = 'set',
delete = 'delete',
}
export enum EArrayMutation {
set = 'set',
delete = 'delete',
push = 'push',
reverse = 'reverse',
shift = 'shift',
unshift = 'unshift',
}
- value - the new data that was added. Varies on type.
type TObjectMutation = {
mutated: EMutated.object;
targetChain: TTarget[];
} & ({
type: EObjectMutation.set;
value: JSONValue;
} | {
type: EObjectMutation.delete;
value?: never;
});
type TArrayMutation = {
mutated: EMutated.array;
targetChain: TTarget[];
} & ({
type: EArrayMutation.set;
value: JSONValue;
} | {
type:
EArrayMutation.push |
EArrayMutation.unshift;
value: JSONValue[];
} | {
type:
EArrayMutation.delete |
EArrayMutation.reverse |
EArrayMutation.shift;
value?: never;
});
The joined type for all of this will be
type TMutation = TObjectMutation | TArrayMutation;