samchon / typia

Super-fast/easy runtime validators and serializers via transformation
https://typia.io/
MIT License
4.6k stars 158 forks source link

Add some kind of configuration to disable the use of BigInt #1152

Closed abrouaux closed 4 months ago

abrouaux commented 4 months ago

- A description of the problem you're trying to solve. We use Typia to generate JSON validation code. Our apps are intended to be executed on smart TVs (LG, Samsung, Hisense, etc). Each TV has a browser that can't be updated, and usually is something a bit older than the year the TV started selling.

Therefore, our applications use polyfills and transpile everything to ES5 to ensure proper execution on all the TVs we need to support.

Trouble is, the Typia library uses BigInt directly in some places. For instance, the first crash we get is in the $ProtobufReader because of those global declarations:

const N01 = /** @__PURE__ */ BigInt(0x01);
const N7F = /** @__PURE__ */ BigInt(0x7f);
const N80 = /** @__PURE__ */ BigInt(0x80);

- An overview of the suggested solution. It seems that the use of BigInt in the context of Typia is related to validating int64 & uint64 tags. Most libraries on NPM have conditional tests on typeof BigInt !== undefined before trying to use those. Would it be possible to do the same?

samchon commented 4 months ago

Upgrade to v6.4.3, then the bug be fixed.

abrouaux commented 4 months ago

Awesome, thanks @samchon for such a fast turnaround, much appreciated!

It now works. I guess I should not try to ensure a int64 or uint64 format right?

samchon commented 4 months ago

The global variable level BigInt types are used for protobuf feature.

If you don't declare bigint type and do not use protobuf feature, you never meet the BigInt type.