antonmedv/fx · error · Error

Cannot get values of ${typeof x}

Error message

Cannot get values of ${typeof x}

What it means

values(x) returns Object.values and, like keys, accepts any non-null object (arrays return their elements). It throws 'Cannot get values of <type>' for primitives and null — most often null from an absent JSON field or failed lookup.

Source

Thrown at internal/engine/stdlib.js:156

function flatten(x) {
  if (Array.isArray(x)) return x.flat()
  throw new Error(`Cannot flatten ${typeof x}`)
}

function reverse(x) {
  if (Array.isArray(x)) return x.reverse()
  throw new Error(`Cannot reverse ${typeof x}`)
}

function keys(x) {
  if (typeof x === 'object' && x !== null) return Object.keys(x)
  throw new Error(`Cannot get keys of ${typeof x}`)
}

function values(x) {
  if (typeof x === 'object' && x !== null) return Object.values(x)
  throw new Error(`Cannot get values of ${typeof x}`)
}

function list(x) {
  if (Array.isArray(x)) {
    for (const y of x) console.log(y)
    return skip
  }
  throw new Error(`Cannot list ${typeof x}`)
}

function del(key) {
  return function (x) {
    if (Array.isArray(x)) {
      const copy = [...x]
      copy.splice(key, 1)
      return copy
    }
    if (typeof x === 'object' && x !== null) {

View on GitHub (pinned to 4f31cd3a0c)

Solutions

  1. Coerce null to an empty object: values(x ?? {})
  2. Guard with x != null before calling values
  3. For a Map, convert first: Array.from(x.values())
  4. Try/catch when the value's shape is not guaranteed

Example fix

// before
const vs = values(resp.data)
// after
const vs = values(resp?.data ?? {})
Defensive patterns

Strategy: fallback

Validate before calling

if (x == null || typeof x !== 'object') throw new TypeError('values() requires a non-null object; got ' + (x === null ? 'null' : typeof x))

Type guard

function hasValues(x) { return x !== null && typeof x === 'object' }

Try / catch

let vs; try { vs = values(x) } catch (e) { if (e.message.startsWith('Cannot get values of')) { vs = [] } else { throw e } }

Prevention

When it happens

Trigger: values(null), values(42), values('abc'), values(undefined), values(true).

Common situations: Extracting values from an API response envelope that came back null/undefined, or passing a Map/Set (not a plain object — Map requires [...map.values()]).

Related errors


AI-assisted analysis of antonmedv/fx@4f31cd3a0c (2026-09-02). Data as JSON: /api/errors/b7ab0075f09a0376. Report an issue: GitHub.