diff --git a/src/structs/types.ts b/src/structs/types.ts index 0587f78a..c1cfccfa 100644 --- a/src/structs/types.ts +++ b/src/structs/types.ts @@ -499,11 +499,12 @@ export function type( }, validator(value) { return ( - isObject(value) || `Expected an object, but received: ${print(value)}` + isNonArrayObject(value) || + `Expected an object, but received: ${print(value)}` ) }, coercer(value) { - return isObject(value) ? { ...value } : value + return isNonArrayObject(value) ? { ...value } : value }, }) } diff --git a/test/validation/type/invalid-array.ts b/test/validation/type/invalid-array.ts new file mode 100644 index 00000000..a0ec3972 --- /dev/null +++ b/test/validation/type/invalid-array.ts @@ -0,0 +1,15 @@ +import { type } from '../../../src' + +export const Struct = type({}) + +export const data = [] + +export const failures = [ + { + value: [], + type: 'type', + refinement: undefined, + path: [], + branch: [data], + }, +]