devtypes - v2.0.0
    Preparing search index...

    Type Alias IsJSONSerializable<T>

    IsJSONSerializable: T extends JSONPrimitive
        ? true
        : T extends bigint
        | symbol
            ? false
            : T extends readonly (infer U)[]
                ? IsJSONSerializable<U>
                : T extends object
                    ? false extends { [K in keyof T]: IsJSONSerializable<T[K]> }[keyof T]
                        ? false
                        : true
                    : true

    Type guard: detect whether a type is JSON serializable.

    Type Parameters

    • T

      Type to test

    Recursively inspects the structure of T to ensure all components are compatible with JSON serialization rules.

    Loose check: functions are considered non-serializable, but JSON.stringify will allow them (they get stripped).

    Will not detect cyclic references in objects.

    type A = IsJSONSerializable< { a: string; b: number[] } >;  // true
    type B = IsJSONSerializable< symbol >; // false