{"record":{"id":"972f179064152b1b","repo":"neon-bindings/neon","slug":"expected-jstypedarray-t","errorCode":null,"errorMessage":"expected JsTypedArray<T>","messagePattern":"expected JsTypedArray<T>","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/neon/src/types_impl/extract/buffer.rs","lineNumber":109,"sourceCode":"    fn try_into_js(self, cx: &mut Cx<'cx>) -> JsResult<'cx, Self::Value> {\n        JsTypedArray::from_slice(cx, self.as_slice())\n    }\n}\n\nimpl<'cx, T> TryFromJs<'cx> for Vec<T>\nwhere\n    JsTypedArray<T>: Value,\n    T: Binary,\n{\n    type Error = TypeExpected<JsTypedArray<T>>;\n\n    fn try_from_js(\n        cx: &mut Cx<'cx>,\n        v: Handle<'cx, JsValue>,\n    ) -> NeonResult<Result<Self, Self::Error>> {\n        let v = match v.downcast::<JsTypedArray<T>, _>(cx) {\n            Ok(v) => v,\n            Err(_) => return Ok(Err(Self::Error::new())),\n        };\n\n        Ok(Ok(v.as_slice(cx).to_vec()))\n    }\n}\n\nimpl<T> private::Sealed for Vec<T>\nwhere\n    JsTypedArray<T>: Value,\n    T: Binary,\n{\n}\n\nimpl<'cx, T, const N: usize> TryIntoJs<'cx> for [T; N]\nwhere\n    JsTypedArray<T>: Value,\n    T: Binary,\n{","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/neon-bindings/neon/blob/38960e4381d9ad13b551cdf2d261f609167c9bc2/crates/neon/src/types_impl/extract/buffer.rs#L91-L127","documentation":"This error is returned by the `TryFromJs` impl for `Vec<u8>` (and typed-array-backed slices): the JS value must downcast to `JsTypedArray<T>`. The message \"expected JsTypedArray<T>\" fires when the value is not a JS typed array view — ArrayBuffers, Buffers (which are Uint8Array but not detected as a generic typed array here), objects, null, or undefined fail the downcast.","triggerScenarios":"Calling an exported Neon function whose parameter extracts as a typed-array-backed `Vec`/slice with a non-typed-array argument: raw ArrayBuffer, DataView, plain object, null, undefined.","commonSituations":"Passing `ArrayBuffer` directly instead of a view over it; passing a Node Buffer created via a path the downcast rejects; passing null for a supposed-optional binary argument.","solutions":["Pass a typed array view: `new Uint8Array(arrayBuffer)` instead of the ArrayBuffer itself","Use `Buffer.from(x)` / `new Uint8Array(x)` in JS to build a typed array before calling","Loosen the Rust parameter to a type accepting all binary shapes, or validate and convert in JS first"],"exampleFix":"// before (JS)\nnative.sumBytes(await file.arrayBuffer());\n// after (JS)\nnative.sumBytes(new Uint8Array(await file.arrayBuffer()));","handlingStrategy":"type-guard","validationCode":"function isTypedArray(x) { return ArrayBuffer.isView(x) && !(x instanceof DataView); }","typeGuard":"function isTypedArray(v) { return v !== null && v !== undefined && ArrayBuffer.isView(v) && !(v instanceof DataView); }","tryCatchPattern":"try { native.sumBytes(arg); } catch (e) { if (String(e).includes('expected JsTypedArray')) { native.sumBytes(new Uint8Array(arg instanceof ArrayBuffer ? arg : arg.buffer)); } else { throw e; } }","preventionTips":["Always pass typed arrays (Uint8Array etc.), never raw ArrayBuffers or DataViews","Use ArrayBuffer.isView() as a cheap pre-call check","Wrap ArrayBuffer in new Uint8Array(...) when the source is a blob or file","Null-check optional binary arguments before the native call"],"tags":["rust","neon","typedarray","extraction","type-error"],"backgroundTag":"type-mismatch","analyzedSha":"38960e4381d9ad13b551cdf2d261f609167c9bc2","analyzedAt":"2026-09-13T09:05:33.640Z","contentChangedAt":"2026-09-13T09:05:33.640Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}