js.Value narrowing methods (asString/asNumber/as*Array) fail to compile: undefined expectType/expectTypedArrayOfType
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- node.js, zig
- Área
- api
Línea de trabajo
Comienza en src/js/value.zig e inspecciona los métodos de narrowing afectados de js.Value y las API de napi para typeof, isTypedarray y getTypedarrayInfo. Confirma que todos los métodos as* indicados compilan, validan su tipo JS o de typed array y devuelven error.TypeMismatch cuando no hay coincidencia; el comando grep del issue puede verificar que se hayan abordado los helpers que faltaban.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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().
- Lenguaje dominante
- Zig
- Estrellas
- 4
- Forks
- 4
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ChainSafe/zapi
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
Type: Maintenance
Dificultad 1/5 Menos de una hora Aptitud para principiantes 76/100
-
clearer errors Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
Todos los issues de ChainSafe/zapi
Issues similares
-
[Bug]: Matrix progress drafts fail with "Matrix runtime not initialized" during tool activity Abiertobug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
AXERA-TECH/ax-llm#77 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
games-on-whales/wolf#509 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100