Type guard that checks if a value is a non-null object.
This function checks if a value has type "object" according to the typeof
operator and is not null. This includes all object types such as plain
objects, arrays, dates, regular expressions, and other object instances, but
excludes functions.
Type Narrowing Behavior:
Narrows unknown to object
Excludes null, undefined, and all primitive types
Excludes functions (they have typeof === "function", not "object")
Includes arrays, dates, regex, and other object instances
Note: This function returns true for arrays. If you need to check for
plain objects specifically (excluding arrays), use isRecord() instead.
Parameters
u: unknown
The value to check
Returns uisobject
true if u is an object and not null, false otherwise. When
true, TypeScript narrows the type to object.
Type guard that checks if a value is a non-null object.
This function checks if a value has type
"object"
according to thetypeof
operator and is notnull
. This includes all object types such as plain objects, arrays, dates, regular expressions, and other object instances, but excludes functions.Type Narrowing Behavior:
unknown
toobject
null
,undefined
, and all primitive typestypeof
==="function"
, not"object"
)Note: This function returns
true
for arrays. If you need to check for plain objects specifically (excluding arrays), useisRecord()
instead.