Skip to content

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

Open
clockwork-labs-bot wants to merge 1 commit intomasterfrom
bot/fix-bool-deserialization
Open

Fix Bool deserialized as number in TS SDK fast path#4596
clockwork-labs-bot wants to merge 1 commit 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.
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

1 participant