Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt not supported but it has been since v4 #125

Closed
dan-online opened this issue Jul 1, 2021 · 2 comments · Fixed by #156
Closed

BigInt not supported but it has been since v4 #125

dan-online opened this issue Jul 1, 2021 · 2 comments · Fixed by #156

Comments

@dan-online
Copy link

Node 16.0.0
Serialize-Javascript 6.0.0
Typescript 4.3.4

I ran into this error today, my first idea is that "BigInt" is weird because I'm using typescript?

Example data: { big: BigInt(0) }

Error:

str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
                   ^
TypeError: Do not know how to serialize a BigInt
@dan-online
Copy link
Author

This repo seems quiet so I'll just post why and close:

Because big is nested in an object, it doesn't go deeper and so BigInt is never serialized

@momocow
Copy link
Contributor

momocow commented Jan 12, 2023

Nop, it DOES go deeper with replacer; however, no other bigint but 0n passes through the replacer without being serialized due to the following condition, which returns the 0n directly.

if (!value && value !== undefined) {
return value;
}

Other bigints are serialized as expected.

Also see #154

momocow added a commit to momocow/serialize-javascript that referenced this issue Jan 12, 2023
okuryu pushed a commit that referenced this issue Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants