The value to check.
true
if the check passes, false
otherwise.
This function will return false
for an array
. If you
do not want this behavior, use isObjectLoose instead.
isObject({}) // true
isObject([]) // false
isObject(null) // false
const value: { foo: string } | string[]
if (isObject(value)) {
value // type: { foo: string }
} else {
value // type: string[]
}
// works with function too
const value: { foo: string } | (() => string)
if (isObject(value)) {
value // type: { foo: string }
value.foo // ok
} else {
value // (() => string)
value() // ok
}
import { assert } from 'uft'
const options: { opt: string } | string[]
assert(isObject(options), 'expected options object')
options // type: { opt: string }
Generated using TypeDoc
Checks if a value is
typeof object
and notnull
or anarray
.