#26

fix(expr): Object.keys/values/entries accept strings and arrays

Opencodewithkenzowants to merge intofrom

Object.keys, Object.values and Object.entries throw Expected an object for strings and arrays, while plain JS returns their index keys. Models write Object.keys(result) on tool output fairly often, and when that output is text or a list the script fails on a message that doesn't say what it got.

Summary

 Object.keys(v)
-  v is not a plain object        -> "Expected an object"
+  v is null or undefined         -> "Object.keys expects an object, got null"
+  anything else                  -> same as JS (strings/arrays give index keys)

Only keys, values and entries change. fromEntries and groupBy keep their checks.

Evidence

  • Before: Object.keys("ab") -> ExprError: Expected an object (new test fails on main)
  • After: ["0", "1"]; Object.values([1, 2]) -> [1, 2]; Object.keys(null) -> Object.keys expects an object, got null

vitest run: 283 passed. tsc --noEmit and biome check clean.

Merge Danger

Door: two-way

Blast Radius: small. Scripts that relied on the throw for strings/arrays now get keys instead. Heads-up: #6 adds an Object.assign that calls asRecord, which this PR renames to asKeyed, so whichever lands second needs a one-line touch. Happy to rebase.

Thanks for callscript!

Activity

2
vercel[bot]1mo ago

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.