/** * Type representing a JSON serializable object. */ export type JSONState = { [key: string]: string | boolean | number | undefined | JSONState | Array } /** * Returns true if the given object can be JSON serialized. * @param what * @return boolean */ export function isJSONState(what: any): what is JSONState { try { JSON.stringify(what) return true } catch (e) { return false } } /** * Base interface for a class that can be rehydrated and restored. */ export interface Rehydratable { /** * Dehydrate this class' state and get it. * @return Promise */ dehydrate(): Promise /** * Rehydrate a state into this class. * @param {JSONState} state * @return void|Promise */ rehydrate(state: JSONState): void | Promise }