Function assertIsObject

Asserts that the input is an object.

An error with message "Expected an object" if the input is not an object.

const fn = (x: Date | { foo: string} | number | string) => {
assertIsObject(x);
return x; // x has inferred type Date | { foo: string } as both comply with object type
};
  • Parameters

    • x: unknown

      The input to be asserted.

    Returns asserts x is object