feat(js): add exact u64 conversion - #80
Conversation
🤖 I have created a release *beep* *boop* --- ## [4.1.0](zapi-v4.0.0...zapi-v4.1.0) (2026-09-25) ### Features * **js:** add exact u64 conversion ([#80](#80)) ([7626863](7626863)) * **js:** add js.spawn async task DSL ([#76](#76)) ([e60cca6](e60cca6)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
1. The name promises a range the function never returns in that range
toU64Exact maxes out at 2^53−1, everything from 2^53 to 2^64−1 throws. The doc comment says so, but the name sets the opposite expectation, and it sets it specifically because toU32Exact right above it is exact across its whole nominal range. Two parallel names, two different contracts.
So I suggest to keep the behaviour but change the name. toSafeInteger(), toU53Exact(), or just return u53 so the signature carries the cap instead of the prose.
2. It doesn't quite unblock the call site it came from
valueToU64 in lodestar-z#648 maps +Infinity -> maxInt(u64), that's how our chain configs spell "fork not scheduled". toU64Exact throws on Infinity, so the call site still needs a wrapper:
fn valueToU64(n: js.Number) !u64 {
const d = try n.toF64();
if (std.math.isPositiveInf(d)) return std.math.maxInt(u64);
return n.toU64Exact() catch return error.InvalidChainConfigFieldValue;
}Good addition, just worth saying the extraction is partial rather than a drop-in.
ChainSafe/lodestar-z#648 (comment)