Skip to content

Commit

Permalink
Fix incorrectly passing validation when arrays are passed to record()
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmuller committed Jun 30, 2024
1 parent 7ab975c commit e9c0341
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/structs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ export function record<K extends string, V>(
},
validator(value) {
return (
isObject(value) || `Expected an object, but received: ${print(value)}`
isNonArrayObject(value) ||
`Expected an object, but received: ${print(value)}`
)
},
})
Expand Down
15 changes: 15 additions & 0 deletions test/validation/record/invalid-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { record, string, number } from '../../../src'

export const Struct = record(string(), number())

export const data = []

export const failures = [
{
value: [],
type: 'record',
refinement: undefined,
path: [],
branch: [data],
},
]

0 comments on commit e9c0341

Please sign in to comment.