/**
 * Shallowly compare two objects.
 */
export function shallowEqual<T extends Record<PropertyKey, unknown>>(
  object1: T | null | undefined,
  object2: T | null | undefined,
): boolean {
  if (object1 === object2) {
    return true;
  }
  const keys1 = Object.keys(object1 ?? {});
  const keys2 = Object.keys(object2 ?? {});
  if (keys1.length !== keys2.length) {
    return false;
  }
  for (const key of keys1) {
    // We'd love to be all proper and use a type predicate earlier, but:
    // https://github.com/microsoft/TypeScript/issues/26916
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    if (object1![key] !== object2![key]) {
      return false;
    }
  }
  return true;
}
