Skip to content

Commit

Permalink
Fix a bug whereby null was wrongly recognised as of type object
Browse files Browse the repository at this point in the history
  • Loading branch information
iliocatallo committed May 2, 2024
1 parent b08c661 commit 5f8968c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/isValid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function isValidLiteral(schema: LiteralSchema, value: any): boolean {
}

function isValidObject(schema: ObjectSchema, value: any): boolean {
if (typeof value !== 'object') {
if (typeOf(value) !== 'object') {
return false
}

Expand Down
8 changes: 8 additions & 0 deletions src/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ test(`object marks optional fields by ending keys with ?`, function () {
assert.is(res3, true)
})

test(`null is not an object`, function () {
const obj = object({})

const res = isValid(obj, null)

assert.is(res, false)
})

test.run()

0 comments on commit 5f8968c

Please sign in to comment.