#1630·valibot

record accepts arrays and returns them as objects

Author: mertcanaltinCreated Sep 9, 2026Updated Sep 9, 2026
Labelsintended

v.record(v.string(), v.number()) accepts arrays and returns them as plain objects.

typescript
const schema = v.record(v.string(), v.number())

v.safeParse(schema, []).output      // {}
v.safeParse(schema, [1, 2]).output  // { '0': 1, '1': 2 }
v.safeParse(schema, ['a']).success  // false

array indices are strings and the values pass the value schema, so it goes through. the input is an array but the output is an object, which is easy to miss.

@valibot/to-json-schema disagrees with this. for the same schema it emits type: "object", so the emitted schema rejects what valibot accepts:

json
{ "type": "object", "propertyNames": { "type": "string" }, "additionalProperties": { "type": "number" } }

that only matters once the emitted schema is used somewhere else, openapi or a gateway, but there the two stop agreeing on the same document.

not sure which side is meant to change. flagging it because they don't match.

valibot 1.4.2, @valibot/to-json-schema 1.7.1