Repository navigation
fix(util): render bigints correctly in printable error messages - #1626
Merged
ssalbdivad merged 4 commits intoOct 1, 2026
Merged
ssalbdivad merged 4 commits into
ssalbdivad merged 4 commits into
Conversation
When bigint values appeared nested inside arrays or objects, `printable()` would output them as quoted strings (e.g. `["1n","0n","1n"]`) instead of the correct unquoted bigint notation (`[1n,0n,1n]`). Root cause: the default path in `printable()` used `JSON.stringify` on the output of `_serialize()`, which converted bigints to plain strings before `JSON.stringify` could see them, causing the strings to be double-quoted. Fix: replace `JSON.stringify(_serialize(...))` with a new `_printableStringify` helper that builds the JSON-like string directly, emitting `Xn` for bigint values instead of converting them to strings first. Closes arktypeio#1477
Contributor
There was a problem hiding this comment.
Reviewed changes — fixes bigint rendering inside arrays/objects in printable(), replacing a _serialize + JSON.stringify round-trip with a direct string builder that emits Xn for bigints inline.
- Add
_printableStringifyhelper — a recursive JSON-like string builder that bypasses_serialize's lossy bigint→string conversion andJSON.stringify's quoting of those strings. - Add bigint-in-array and bigint-in-object tests — two focused snapshot tests covering the fixed paths.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Rather than reimplementing JSON serialization, keep the existing _serialize + JSON.stringify path and have printableOpts serialize bigints with a private-use marker prefix, then strip the quotes JSON.stringify adds around marked values. This fixes arktypeio#1477 without changing how functions, sparse arrays or toJSON results print. Adds the issue's repro as an error message test. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
4 tasks done
ssalbdivad
added a commit
that referenced
this pull request
Oct 1, 2026
Bumps all publishable packages and documents the changes merged since 2.2.6: - fix `this[]` in self-referential object types (#1618, fixes #1406, @yharaskrik) - parse string.date.epoch.parse input as milliseconds (#1669, @breken-ai) - keep uppercase UUIDs valid in string.uuid JSON Schema (#1670, @breken-ai) - render nested bigints correctly in error messages (#1626, fixes #1477, @chatman-media) - release unused parse ids from the global registry (#1673, fixes #1584 for equivalent types, @isaacwasserman) - fix crashes on Hermes and Turbopack (#1674, fixes #1645 and #1643) #1590 only adds tests, so it has no changelog entry. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
ssalbdivad
pushed a commit
that referenced
this pull request
Oct 27, 2026
printable serialized a nested undefined as the string "undefined", so
JSON.stringify quoted it and {a: undefined} printed the same as
{a: "undefined"}. Mark it the same way #1626 marks bigints and strip
the quotes.
Co-authored-by: youdie006 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Closes #1477
When bigint values appear nested inside arrays or objects,
printable()emitsthem as quoted strings (e.g.
["1n","0n","1n"]) instead of the correctunquoted bigint notation (
[1n,0n,1n]). Top-level bigints (e.g.printable(1n)) were already correct.Root cause
The default path in
printable()serialised values with_serialize()thenpassed the result to
JSON.stringify():_serialize()converts bigints to plain strings ("1n") becauseprintableOptsdefines noonBigInthandler.JSON.stringifythen wrapsthose strings in quotes, producing
"\"1n\""inside arrays/objects.Fix
Replace
JSON.stringify(_serialize(...))with a new_printableStringifyhelper that builds the JSON-like string directly. It emits
Xnfor bigints(same as
serializePrimitive) and falls back toJSON.stringifyfor all otherscalar types, preserving the existing output format exactly:
{"a":1}, not{a: 1})quoteKeys: falsestill delegates to the existingstringifyUnquotedpathTest evidence
Two new tests in
ark/util/__tests__/printable.test.ts:All 128 util tests pass. Schema and type package tests unchanged.