import type { Option } from '../fp/Option'; export type JSONPrimitive = string | number | boolean | null | undefined; export interface JSONObject extends Record { } export interface JSONArray extends ReadonlyArray { } export type JSONValue = JSONPrimitive | JSONObject | JSONArray; /** Like Date object, Moment object, luxon.DateTime object */ export interface ValueContainer { valueOf: () => A; } type ExcludeFunctions = ExcludeKeysOfType; type ValidProps = ExcludeFunctions>>; type JSONArrayOf> = IsReadonly extends true ? readonly Jsonify[] : Jsonify[]; type Optional> = { [P in Exclude>, OmitKeys>]?: Jsonify; }; type NonOptional> = { [P in keyof ValidProps>, OmitKeys>]: Jsonify; }; type JSONObjectOf> = keyof ValidProps extends never ? A extends ValueContainer ? R : {} : Optional & NonOptional; type ExtractKeys = A extends Option ? ExtractKeys : A extends JSONSerializable ? ExtractKeys : A extends readonly (infer T)[] ? ExtractKeys : A extends AnyObject ? keyof A : never; export type Jsonify = never> = A extends Option ? Jsonify>> | undefined : A extends JSONSerializable ? Jsonify>> : A extends readonly (infer T)[] ? JSONArrayOf>> : A extends Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array ? number[] : A extends AnyObject ? JSONObjectOf : A extends JSONValue ? A : string; export interface JSONSerializable = never> { /** * Just for correct infering: https://github.com/Microsoft/TypeScript/issues/26688 * It's required to define in implementation for correct typing with `JSONModel`. * It might be just equals `this`. */ readonly _serializable: JSONSerializable; toJSON(): Jsonify; } export {};