Function isPlainObject

    • Type Parameters

      • T extends object

      Parameters

      • value: T

      Returns value is T

    • Determines whether a value is a plain object.

      A plain object is one whose prototype is either:

      • Object.prototype (created via {} or new Object())
      • null (created via Object.create(null))

      This excludes arrays, functions, class instances, DOM objects, and any object with a custom prototype. In other words, this function detects JSON-like dictionary objects rather than structural or callable object types.

      Type Behavior:

      • If the input already has a known object type T, that type is preserved after narrowing.
      • If the input is unknown or untyped the result narrows to Record<string, unknown> allowing safe keyed access.

      Useful when validating configuration objects, cloning or merging data, performing deep equality, or working with structured JSON where non-plain / prototype values would be considered invalid.

      Parameters

      • value: unknown

        Any value to evaluate.

      Returns value is Record<string, unknown>

      True if the value is a plain object with no special prototype.

      const a = { x: 1 };
      isPlainObject(a); // true

      class Foo {}
      isPlainObject(new Foo()); // false
      let data: unknown = getValue();
      if (isPlainObject(data)) {
      data.foo; // ok — key is `unknown`, but structure is guaranteed.
      }