You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
547 B
18 lines
547 B
// Type that survives being serialized to json and back
|
|
export type StringifiableValue =
|
|
| string
|
|
| number
|
|
| boolean
|
|
| null
|
|
| undefined
|
|
| StringifiableValue[]
|
|
| {
|
|
[key: string]: StringifiableValue;
|
|
};
|
|
|
|
// To be used instead of JSON.stringify / JSON.parse everywhere, in order to ensure that values are of stringifiable type
|
|
export const createSerializer = <TValue extends StringifiableValue>() =>
|
|
JSON as {
|
|
stringify(value: TValue): string;
|
|
parse(serialized: string): TValue;
|
|
};
|
|
|