Function safeParse

  • Parses a JSON string to the specified type.

    Type Parameters

    • T

      The type of the returned object.

    Parameters

    • guard: ((o) => o is T)

      The type predicate to validate the deserialized object.

        • (o): o is T
        • Parameters

          • o: unknown

          Returns o is T

    • json: string

      The JSON string to parse.

    Returns T | undefined

    The desrialized object, if the type guard function returns true; otherwise, undefined.