You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON.stringify should disallow BigInt value #63333
JSON.stringify is correctly marked with @throws {TypeError} If a circular reference or a BigInt value is found., but it types its input value parameter as any. That type could be improved so that BigInt can't even be passed into the function (turning one runtime error into a compiletime error).
Perhaps even every type that contains a BigInt can and should be excluded. I'm not very good at TypeScript but that might be possible.
Note that if a replacer function is specified, this complicates the situation somewhat.
This issue is distinct from the perennial proposal to correctly treat undefined in JSON.stringify (eg #18879). Hopefully, the false-positive impact of this one should be much lower, and thus it can be accepted.
Sample Code
//These are runtime errors, but TypeScript doesn't complain.//"Uncaught TypeError: Do not know how to serialize a BigInt"JSON.stringify(1n);JSON.stringify([1n]);
What type would the argument to JSON.stringify have? If it tried to list only things that were guaranteed to be JSON stringifyable, that would be #1897. If you wanted Exclude<unknown, bigint>, that would be #4196.
Activity
nmain commentedon Apr 2, 2026
What type would the argument to
JSON.stringifyhave? If it tried to list only things that were guaranteed to be JSON stringifyable, that would be #1897. If you wantedExclude<unknown, bigint>, that would be #4196.typescript-bot commentedon Apr 5, 2026
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.