isPlainObject
Checks whether a value is a plain object. A plain object is one created with {} or new Object(), where the prototype is exactly Object.prototype.
This helper excludes null, arrays, class instances, and objects with custom prototypes. It never throws and never mutates input.
Signature
function isPlainObject(value: unknown): value is object
Parameters
| Name | Data type | Description |
|---|---|---|
| value | unknown |
The value to check. Must be a non‑null object whose prototype is exactly Object.prototype to return true |
Returns
A boolean:
true: If the value is a non‑null object withObject.prototypeas its prototype.false: Otherwise.
Examples
isPlainObject({}) // true
isPlainObject({ a: 1 }) // true
isPlainObject(new Object()) // true
isPlainObject([]) // false
isPlainObject(null) // false
isPlainObject(Object.create(null)) // false
isPlainObject(new Date()) // false
isPlainObject(class X {}) // false
isPlainObject(new (class Y {})()) // false
Notes
- This helper is stricter than isObject. Use
isObjectif you only need to excludenulland arrays. - Use
normalizeObjectif you need to ensure the value becomes an object. - Use
validateObjectif you need aResult<T>instead of a boolean.