vitest-dev/vitest · error · Error

value of unknown type: ${value}

Error message

value of unknown type: ${value}

What it means

Thrown by getType() in packages/utils/src/diff/getType.ts as a defensive guard at the end of the type-discrimination ladder. The function handles undefined, null, array, boolean, function, number, string, bigint, object (with regexp/map/set/date subtypes), and symbol. Falling through every branch means typeof returned a value TypeScript's union doesn't model — practically only reachable via a host quirk, a Proxy returning an exotic typeof, or a corrupted runtime.

Source

Thrown at packages/utils/src/diff/getType.ts:65

        return 'regexp'
      }
      else if (value.constructor === Map) {
        return 'map'
      }
      else if (value.constructor === Set) {
        return 'set'
      }
      else if (value.constructor === Date) {
        return 'date'
      }
    }
    return 'object'
  }
  else if (typeof value === 'symbol') {
    return 'symbol'
  }

  throw new Error(`value of unknown type: ${value}`)
}

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Inspect the actual value passed to the differ and its typeof result in a debugger.
  2. Remove any Proxy or Symbol.toPrimitive/toStringTag overrides that may distort typeof.
  3. Update to a supported Node version (^20 || ^22 || >=24).
  4. File a Vitest issue with a minimal reproduction if the value is a plain object/function.
Defensive patterns

Strategy: try-catch

Validate before calling

function safeGetType(value: unknown): string {
  try { return getType(value) } catch { return 'unknown' }
}

Type guard

function isKnownType(value: unknown): boolean {
  try { getType(value); return true } catch { return false }
}

Try / catch

try {
  // diff/serialization path that calls getType
} catch (err) {
  if (err.message.startsWith('value of unknown type')) {
    // log the value's typeof and prototype for diagnosis, fall back to String(value)
  } else throw err
}

Prevention

When it happens

Trigger: Passing a value from a Proxy whose typeof hook returns an exotic string; crossing realms where typeof behaves oddly; very old or non-conformant engines; values patched by tooling that changes typeof semantics.

Common situations: Effectively unreachable in standard V8/Node — usually indicates a tampered environment, a sandbox escape, or a bug in a serializer/differ invoked with a value whose prototype chain was mutated.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/3b2bc49610220bfc.json. Report an issue: GitHub.