{"record":{"id":"b7ab0075f09a0376","repo":"antonmedv/fx","slug":"cannot-get-values-of-typeof-x","errorCode":null,"errorMessage":"Cannot get values of ${typeof x}","messagePattern":"Cannot get values of (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/engine/stdlib.js","lineNumber":156,"sourceCode":"\nfunction flatten(x) {\n  if (Array.isArray(x)) return x.flat()\n  throw new Error(`Cannot flatten ${typeof x}`)\n}\n\nfunction reverse(x) {\n  if (Array.isArray(x)) return x.reverse()\n  throw new Error(`Cannot reverse ${typeof x}`)\n}\n\nfunction keys(x) {\n  if (typeof x === 'object' && x !== null) return Object.keys(x)\n  throw new Error(`Cannot get keys of ${typeof x}`)\n}\n\nfunction values(x) {\n  if (typeof x === 'object' && x !== null) return Object.values(x)\n  throw new Error(`Cannot get values of ${typeof x}`)\n}\n\nfunction list(x) {\n  if (Array.isArray(x)) {\n    for (const y of x) console.log(y)\n    return skip\n  }\n  throw new Error(`Cannot list ${typeof x}`)\n}\n\nfunction del(key) {\n  return function (x) {\n    if (Array.isArray(x)) {\n      const copy = [...x]\n      copy.splice(key, 1)\n      return copy\n    }\n    if (typeof x === 'object' && x !== null) {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/engine/stdlib.js#L138-L174","documentation":"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.","triggerScenarios":"values(null), values(42), values('abc'), values(undefined), values(true).","commonSituations":"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()]).","solutions":["Coerce null to an empty object: values(x ?? {})","Guard with x != null before calling values","For a Map, convert first: Array.from(x.values())","Try/catch when the value's shape is not guaranteed"],"exampleFix":"// before\nconst vs = values(resp.data)\n// after\nconst vs = values(resp?.data ?? {})","handlingStrategy":"fallback","validationCode":"if (x == null || typeof x !== 'object') throw new TypeError('values() requires a non-null object; got ' + (x === null ? 'null' : typeof x))","typeGuard":"function hasValues(x) { return x !== null && typeof x === 'object' }","tryCatchPattern":"let vs; try { vs = values(x) } catch (e) { if (e.message.startsWith('Cannot get values of')) { vs = [] } else { throw e } }","preventionTips":["Default nullables: values(x ?? {})","Convert Maps with Array.from(map.values()) first","Validate response envelopes before extracting values","Keep null-checks at data ingress, not at each call site"],"tags":["type-error","null","runtime","stdlib"],"backgroundTag":"null-or-undefined-input","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}