TypeScript · Boundaries

TS0014Do not compare prototypes of values from another realm

Report prototype and constructor identity checks against built-in classes on values that may come from another JavaScript realm.

Why it happens

Every realm has its own Object.prototype, Array.prototype and built-in constructors. A plain object or array created by the Vite module runner, workerd or miniflare, or a Vitest environment has that realm's prototype, so Object.getPrototypeOf(value) === Object.prototype or value.constructor === Array is false and the check rejects or misroutes it. This rule only reports values that crossed a boundary in this file: parameters typed unknown or any, results of calling a parameter, and module namespaces from import() or ssrLoadModule().

Fix

Avoid realm identity: use Array.isArray(value) for arrays, Object.getPrototypeOf(prototype) === null for plain objects, or a tag shared by the implementations you support where applicable. Narrow only to the capabilities a member check verifies. If you need full class semantics, validate or normalize the value at the integration boundary.

Example

Check plain objects without Object.prototype

Before

export function isPlainObject(value: unknown): value is Record<string, unknown> {
  if (typeof value !== 'object' || value === null) return false
  const prototype = Object.getPrototypeOf(value)
  return prototype === Object.prototype || prototype === null
}

After

export function isPlainObject(value: unknown): value is Record<string, unknown> {
  if (typeof value !== 'object' || value === null) return false
  const prototype = Object.getPrototypeOf(value)
  return prototype === null || Object.getPrototypeOf(prototype) === null
}

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --extends auto,typescript/strict --rules typescript/boundaries/no-cross-realm-prototype-identity
Copyright © 2026