io-ts icon indicating copy to clipboard operation
io-ts copied to clipboard

`PathReporter` throws when a `bigint` is part of the error messages

Open jonball4 opened this issue 3 years ago • 2 comments

https://github.com/gcanti/io-ts/blob/920b21ea32e82b328cd14ff4b28da72ae60db505/src/PathReporter.ts#L18

This will throw an error when a bigint is involved. Could we use a replacer in this call to handle bigint?

jonball4 avatar Jun 30 '22 16:06 jonball4

@jonball4 could you please provide a repro?

gcanti avatar Aug 04 '22 07:08 gcanti

@gcanti @jonball4 could you please provide a repro?

    interface PositiveBigIntBrand {
      readonly PositiveBigInt: unique symbol
    }

    const PositiveBigInt = t.brand(
      t.bigint,
      (n): n is t.Branded<bigint, PositiveBigIntBrand> => BigInt(0) < n,
      'PositiveBigInt',
    )

    const testC = t.type({ value: PositiveBigInt });
    const testValidation = testC.decode({ value: -10n });

    // This will throw
    const value = PathReporter.report(testValidation);

jonball4 avatar Oct 18 '22 01:10 jonball4