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 → call self.expectType(...)
asInt8Array, asUint8Array, asUint8ClampedArray, asInt16Array, asUint16Array, asInt32Array, asUint32Array, asFloat32Array, asFloat64Array, asBigInt64Array, asBigUint64Array → call self.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().
Summary
In
js.Value, every type-narrowing method callsself.expectType(...)(orself.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(...)asArrayandasDateare not affected — they useself.val.isArray()/self.val.isDate()directly.A grep confirms the helpers are referenced but never declared:
Compile error
Minimal reproduction
Expected behavior
The narrowing methods should compile and validate the underlying JS type, returning
error.TypeMismatchon a mismatch (as their doc comments state).Likely fix
Add the missing private helpers to
Value, e.g.:(Field/method names should be matched to the actual
napiAPI.)Workaround
Construct the DSL wrapper directly and skip the
as*validation, e.g.js.String{ .val = napi_value }instead ofvalue.asString().