Skip to content

Fix Bool deserialized as number in TS SDK fast path#4596

Merged
bfops merged 2 commits intomasterfrom
bot/fix-bool-deserialization
Mar 10, 2026
Merged

Fix Bool deserialized as number in TS SDK fast path#4596
bfops merged 2 commits intomasterfrom
bot/fix-bool-deserialization

Conversation

@clockwork-labs-bot
Copy link
Collaborator

Fixes #4591

Root Cause

The isFixedSizeProduct fast-path deserializer in algebraic_type.ts maps Bool to view.getUint8(), which returns a number (0 or 1) instead of a JavaScript boolean. The slow path (reader.readBool()) correctly converts via !== 0.

This means any product type containing only fixed-size primitives (bools, ints, floats) hits the fast path and returns numbers for boolean fields. Products containing strings, arrays, or nested objects go through the slow path and work correctly.

This explains the inconsistency in the issue: a flat { foo: bool } returns { foo: 1 }, but adding a nested object pushes it to the slow path where foo becomes true (though the nested bool still hits the fast path within its own product).

Fix

Special-case Bool in the fast-path code generation to emit:

result.foo = view.getUint8(reader.offset) !== 0;

instead of:

result.foo = view.getUint8(reader.offset);

One-line change in the ternary within makeDeserializer.

The isFixedSizeProduct fast-path deserializer used view.getUint8()
for Bool fields, which returns a number (0 or 1) instead of a
boolean. The slow path (reader.readBool()) correctly uses !== 0.

Fix: special-case Bool in the fast path to emit:
  result.foo = view.getUint8(reader.offset) !== 0;
instead of:
  result.foo = view.getUint8(reader.offset);

This caused useTable to return {foo: 1} instead of {foo: true}
for products containing only fixed-size primitives.
@clockwork-labs-bot clockwork-labs-bot added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@bfops bfops enabled auto-merge March 10, 2026 16:39
@bfops bfops disabled auto-merge March 10, 2026 16:39
@bfops bfops added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@bfops bfops added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@bfops bfops added this pull request to the merge queue Mar 10, 2026
Merged via the queue into master with commit c7ef234 Mar 10, 2026
55 of 56 checks passed
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 this pull request may close these issues.

TypeScript / React useTable returns number instead of bool

5 participants