js.Value narrowing methods (asString/asNumber/as*Array) fail to compile: undefined expectType/expectTypedArrayOfType
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- node.js, zig
- Domain
- api
Research direction
Start in src/js/value.zig and inspect the affected js.Value narrowing methods and the napi APIs for typeof, isTypedarray, and getTypedarrayInfo. Confirm that all listed as* methods compile, validate their JS or typed-array type, and return error.TypeMismatch on mismatches; the grep command in the issue can verify the missing helpers are addressed.
Written by the indexing model from the issue text.
Description
Summary
In js.Value, every type-narrowing method calls self.expectType(...) (or self.expectTypedArrayOfType(...)), but neither helper is defined anywhere in the package. As a result, referencing any of these methods is a hard compile error.
Observed on zapi 2.2.0 (src/js/value.zig).
Affected methods
All of these reference the missing helpers:
asNumber,asString,asBoolean,asBigInt,asFunction,asObject→ callself.expectType(...)asInt8Array,asUint8Array,asUint8ClampedArray,asInt16Array,asUint16Array,asInt32Array,asUint32Array,asFloat32Array,asFloat64Array,asBigInt64Array,asBigUint64Array→ callself.expectTypedArrayOfType(...)
asArray and asDate are not affected — they use self.val.isArray() / self.val.isDate() directly.
A grep confirms the helpers are referenced but never declared:
$ grep -rnE 'fn expectType\b|fn expectTypedArrayOfType\b' src/
# (no matches)
Compile error
src/js/value.zig:117:17: error: no field or member function named 'expectType' in 'js.value.Value'
try self.expectType(.string);
^~~~~~~~~~
Minimal reproduction
const js = @import("zapi:zapi").js;
// Referencing any narrowing method triggers the error:
pub fn parse(v: js.Value) !void {
const s = try v.asString(); // error: no member function named 'expectType'
_ = s;
}
Expected behavior
The narrowing methods should compile and validate the underlying JS type, returning error.TypeMismatch on a mismatch (as their doc comments state).
Likely fix
Add the missing private helpers to Value, e.g.:
fn expectType(self: Value, expected: napi.value_types.ValueType) !void {
if ((try self.val.typeof()) != expected) return error.TypeMismatch;
}
fn expectTypedArrayOfType(self: Value, expected: napi.value_types.TypedarrayType) !void {
if (!(try self.val.isTypedarray())) return error.TypeMismatch;
const info = try self.val.getTypedarrayInfo();
if (info.type != expected) return error.TypeMismatch;
}
(Field/method names should be matched to the actual napi API.)
Workaround
Construct the DSL wrapper directly and skip the as* validation, e.g. js.String{ .val = napi_value } instead of value.asString().
- Dominant language
- Zig
- Stars
- 4
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ChainSafe/zapi
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Type: Maintenance
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
clearer errors Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
Similar issues
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100