zloirock/core-js · error · TypeError
Target is not a typed array
Error message
Target is not a typed array
What it means
aTypedArray is core-js's internal spec-op guard used by every typed-array method it polyfills. If the receiver's internal class is not in the typed-array constructors list (Int8Array ... Float64Array, BigInt64Array, etc.), it throws 'TypeError: Target is not a typed array'. This mirrors the spec's ValidateTypedArray / RequireInternalSlot([[TypedArrayName]]) requirement.
Source
Thrown at packages/core-js/internals/array-buffer-view-core.js:80
};
var getTypedArrayConstructor = function (it) {
var proto = getPrototypeOf(it);
if (!isObject(proto)) return;
var state = getInternalState(proto);
return (state && hasOwn(state, TYPED_ARRAY_CONSTRUCTOR)) ? state[TYPED_ARRAY_CONSTRUCTOR] : getTypedArrayConstructor(proto);
};
var isTypedArray = function (it) {
if (!isObject(it)) return false;
var klass = classof(it);
return hasOwn(TypedArrayConstructorsList, klass)
|| hasOwn(BigIntArrayConstructorsList, klass);
};
var aTypedArray = function (it) {
if (isTypedArray(it)) return it;
throw new TypeError('Target is not a typed array');
};
var aTypedArrayConstructor = function (C) {
if (isCallable(C) && (!setPrototypeOf || isPrototypeOf(TypedArray, C))) return C;
throw new TypeError(tryToString(C) + ' is not a typed array constructor');
};
var exportTypedArrayMethod = function (KEY, property, forced, options) {
if (!DESCRIPTORS) return;
if (forced) for (var ARRAY in TypedArrayConstructorsList) {
var TypedArrayConstructor = globalThis[ARRAY];
if (TypedArrayConstructor && hasOwn(TypedArrayConstructor.prototype, KEY)) try {
delete TypedArrayConstructor.prototype[KEY];
} catch (error) {
// old WebKit bug - some methods are non-configurable
try {
TypedArrayConstructor.prototype[KEY] = property;
} catch (error2) { /* empty */ }View on GitHub (pinned to 84e45fba09)
Solutions
- Pass a genuine typed array (Int8Array, Uint8Array, Float32Array, BigInt64Array, etc.).
- If you have a plain array, convert it first: new Float64Array(arr).
- If you have an ArrayBuffer, create a view: new Uint8Array(buffer).
- Check the receiver binding: methods must be invoked as arr.method(...), not detached via .call with a wrong this.
Example fix
// before Uint8Array.prototype.set.call(plainArray, src); // TypeError: Target is not a typed array // after new Uint8Array(plainArray).set(src);
Defensive patterns
Strategy: type-guard
Validate before calling
function isTypedArray(v){ return ArrayBuffer.isView(v) && !(v instanceof DataView); }
if (!isTypedArray(receiver)) throw new TypeError('receiver must be a typed array'); Type guard
function isTypedArray(v){ return v instanceof Int8Array || v instanceof Uint8Array || v instanceof Uint8ClampedArray || v instanceof Int16Array || v instanceof Uint16Array || v instanceof Int32Array || v instanceof Uint32Array || v instanceof Float32Array || v instanceof Float64Array || (typeof BigInt64Array !== 'undefined' && v instanceof BigInt64Array) || (typeof BigUint64Array !== 'undefined' && v instanceof BigUint64Array); } Try / catch
try { typedArrayMethod.call(recv, ...args); } catch (e) { if (/Target is not a typed array/.test(e.message)) { recv = new Uint8Array(recv.buffer || recv); retry(); } else throw e; } Prevention
- Don't detach typed-array methods from their receiver.
- Convert plain arrays with new XArray(arr) before calling typed-array methods.
- A DataView is not a typed array — pass a real view type.
- Beware mocks in tests: ArrayBuffer.isView alone passes for DataView too.
When it happens
Trigger: Calling a typed-array method (e.g. %TypedArray%.prototype.slice/set/subarray/fill) with `this` set to a plain Array, ArrayBuffer, DataView, or non-object via .call/.apply, or calling a polyfilled standalone helper with a non-typed-array argument.
Common situations: Manual this-binding tricks (Array.prototype.slice.call(fakeTypedArray) style code adapted backwards); code that duck-types on .length and passes arrays; mocks in tests that aren't real typed arrays; passing a DataView where a typed array is required.
Related errors
- ArrayBuffer expected
- is not a typed array constructor
- Incorrect invocation
- Incompatible receiver, ${TYPE} required
- Object already initialized
AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30).
Data as JSON: /api/errors/9a1fe42984b738dc.
Report an issue: GitHub.