From c7ef2346a2a4577e8259ef97dd6846aaf41f3a29 Mon Sep 17 00:00:00 2001 From: clockwork-labs-bot Date: Tue, 10 Mar 2026 16:51:25 -0400 Subject: [PATCH] Fix Bool deserialized as number in TS SDK fast path (#4596) 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: ```js result.foo = view.getUint8(reader.offset) !== 0; ``` instead of: ```js result.foo = view.getUint8(reader.offset); ``` One-line change in the ternary within `makeDeserializer`. Co-authored-by: clockwork-labs-bot Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com> --- crates/bindings-typescript/src/lib/algebraic_type.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bindings-typescript/src/lib/algebraic_type.ts b/crates/bindings-typescript/src/lib/algebraic_type.ts index 7ddd3f93d..c325797af 100644 --- a/crates/bindings-typescript/src/lib/algebraic_type.ts +++ b/crates/bindings-typescript/src/lib/algebraic_type.ts @@ -535,7 +535,11 @@ const view = reader.view; ${ty.elements .map(({ name, algebraicType: { tag } }) => tag in primitiveJSName - ? `\ + ? tag === 'Bool' + ? `\ +result.${name} = view.getUint8(reader.offset) !== 0; +reader.offset += 1;` + : `\ result.${name} = view.get${primitiveJSName[tag as JSPrimitives]}(reader.offset, ${primitiveSizes[tag] > 1 ? 'true' : ''}); reader.offset += ${primitiveSizes[tag]};` : `result.${name} = reader.read${tag}();`