zloirock/core-js · error · TypeError

is not a typed array constructor

Error message

 is not a typed array constructor

What it means

aTypedArrayConstructor validates that C is a callable whose prototype chain derives from the intrinsic TypedArray constructor (when setPrototypeOf-based detection works). Otherwise core-js throws a TypeError '<stringified C> is not a typed array constructor'. It guards internal subclassing/exports (e.g. TypedArray.from/of and constructor-dependent method exports).

Source

Thrown at packages/core-js/internals/array-buffer-view-core.js:85

  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 */ }
    }
  }
  if (!TypedArrayPrototype[KEY] || forced) {
    defineBuiltIn(TypedArrayPrototype, KEY, forced ? property
      : NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property, options);

View on GitHub (pinned to 84e45fba09)

Solutions

  1. Use a real typed-array constructor (Uint8Array, Float64Array, ...).
  2. Declare subclasses with native `class X extends Uint8Array` so isPrototypeOf(TypedArray, C) holds.
  3. Ensure core-js's chosen globals aren't shadowed/undefined at call time.
  4. Avoid overriding setPrototypeOf or using es5 transpilation for typed-array subclasses.

Example fix

// before
typedArrayFrom(Array, [1,2,3]); // Array is not a typed array constructor
// after
typedArrayFrom(Float64Array, [1,2,3]);
Defensive patterns

Strategy: validation

Validate before calling

function isTypedArrayCtor(C){ return typeof C === 'function' && ['Int8Array','Uint8Array','Uint8ClampedArray','Int16Array','Uint16Array','Int32Array','Uint32Array','Float32Array','Float64Array','BigInt64Array','BigUint64Array'].some(n => typeof globalThis[n] === 'function' && C === globalThis[n]); }

Type guard

function isTypedArrayCtor(C){ return typeof C === 'function' && Function.prototype.toString.call(C).includes('[native code]') === false ? C.prototype instanceof Object.getPrototypeOf(Uint8Array) : typeof C === 'function' && C.prototype instanceof Object.getPrototypeOf(Uint8Array); }

Try / catch

try { C.from(data); } catch (e) { if (/is not a typed array constructor/.test(e.message)) { C = Float64Array; C.from(data); } else throw e; }

Prevention

When it happens

Trigger: Passing a non-typed-array constructor to APIs expecting one (e.g. calling a polyfilled generic expecting a typed-array constructor), or invoking the export with a subclass not properly linked via extends/setPrototypeOf, or with undefined (often prints 'undefined is not a typed array constructor').

Common situations: Transpilation/down-leveling that breaks `class MyArr extends Uint8Array` prototype linkage (loose mode, broken setPrototypeOf); tooling munging globals so Uint8Array is undefined; passing Array or DataView constructors by mistake.

Related errors


AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30). Data as JSON: /api/errors/fd96fd8a0b9f7442. Report an issue: GitHub.