Do not compare prototypes of values from another realm
typescript/boundaries/no-cross-realm-prototype-identitysrc/rule-packs/typescript/rules/no-cross-realm-prototype-identity.ts Upstream docs Run this rule
pnpm vite-doctor . --extends auto,typescript/strict --rules typescript/boundaries/no-cross-realm-prototype-identity
Why it matters
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().
Recommended 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.
Useful links
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
}