zloirock/core-js · error · TypeError

Incorrect invocation

Error message

Incorrect invocation

What it means

In engines lacking native ArrayBuffer views, core-js installs a placeholder TypedArray base function that only throws 'TypeError: Incorrect invocation' when called. This prevents constructing the abstract TypedArray base directly, mirroring the spec rule that %TypedArray% is not a constructor.

Source

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

for (NAME in TypedArrayConstructorsList) {
  Constructor = globalThis[NAME];
  Prototype = Constructor && Constructor.prototype;
  if (Prototype) enforceInternalState(Prototype)[TYPED_ARRAY_CONSTRUCTOR] = Constructor;
  else NATIVE_ARRAY_BUFFER_VIEWS = false;
}

for (NAME in BigIntArrayConstructorsList) {
  Constructor = globalThis[NAME];
  Prototype = Constructor && Constructor.prototype;
  if (Prototype) enforceInternalState(Prototype)[TYPED_ARRAY_CONSTRUCTOR] = Constructor;
}

// WebKit bug - typed arrays constructors prototype is Object.prototype
if (!NATIVE_ARRAY_BUFFER_VIEWS || !isCallable(TypedArray) || TypedArray === Function.prototype) {
  // eslint-disable-next-line no-shadow -- safe
  TypedArray = function TypedArray() {
    throw new TypeError('Incorrect invocation');
  };
  if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) {
    if (globalThis[NAME]) setPrototypeOf(globalThis[NAME], TypedArray);
  }
}

if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) {
  TypedArrayPrototype = TypedArray.prototype;
  if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) {
    if (globalThis[NAME]) setPrototypeOf(globalThis[NAME].prototype, TypedArrayPrototype);
  }
}

// WebKit bug - one more object in Uint8ClampedArray prototype chain
if (NATIVE_ARRAY_BUFFER_VIEWS && getPrototypeOf(Uint8ClampedArrayPrototype) !== TypedArrayPrototype) {
  setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype);
}

View on GitHub (pinned to 84e45fba09)

Solutions

  1. Instantiate a concrete constructor: new Uint8Array(n), new Float32Array(...), etc.
  2. Never call the abstract %TypedArray% base; it exists only as a prototype hub.
  3. If dynamically choosing a type, index a real list: {u8: Uint8Array, f32: Float32Array}[name].

Example fix

// before
var a = new TypedArray(8); // TypeError: Incorrect invocation
// after
var a = new Uint8Array(8);
Defensive patterns

Strategy: type-guard

Validate before calling

function isConcreteTypedArrayCtor(C){ return C !== Object.getPrototypeOf(Uint8Array) && typeof C === 'function' && Object.getPrototypeOf(C) === Object.getPrototypeOf(Uint8Array); }

Try / catch

try { view = new C(n); } catch (e) { if (/Incorrect invocation/.test(e.message)) throw new Error('use a concrete typed-array constructor, not the %TypedArray% base'); throw e; }

Prevention

When it happens

Trigger: Directly invoking the abstract TypedArray constructor: new TypedArray() or TypedArray() — e.g. via reflect.construct(TypedArray, []) or code that treats TypedArray as a concrete class.

Common situations: Code referencing the exported/internal TypedArray symbol instead of a concrete constructor like Uint8Array; metaprogramming that iterates constructor lists and instantiates the base; misuse of Reflect.construct with the base as target.

Related errors


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