gcanti / io-ts

Runtime type system for IO decoding/encoding
https://gcanti.github.io/io-ts/
MIT License
6.7k stars 328 forks source link

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

Open jonball4 opened 2 years ago

jonball4 commented 2 years ago

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?

gcanti commented 2 years ago

@jonball4 could you please provide a repro?

jonball4 commented 2 years ago

@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);