Function assertPlainObject

    • Asserts that a value is a plain object, not null, and not an array.

      Unlike isPlainObject, this function does not narrow the value to a generic indexable structure. Instead, it preserves the existing static type of the variable. This makes it ideal for validating option objects or interface-based inputs where all properties may be optional.

      Use this function when:

        - You expect a value to be a plain object at runtime, **and**
      - You want to keep its compile-time type intact after validation.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to validate.

      • OptionalerrorMsg: string

        Optional message used for the thrown TypeError.

      Returns asserts value is T & object

      interface Options { flag?: boolean; value?: number; }

      function run(opts: Options = {}) {
      assertPlainObject(opts, `'opts' is not a plain object.`); // `opts` remains `Options`, not widened or reduced.
      opts.value; // Fully typed access remains available.
      }

      if the value is null, non-object, or an array.