score:2

You should assert event.target as HTMLElement or HTMLDivElement.
By the way, You can set event argument as MouseEvent.

So, the right code is below:

const handleClickOutsideDialog = (event: MouseEvent) => {
  if (
    dialogRef &&
    !dialogRef.contains(event.target as HTMLDivElement)
  ) {
    alert('You clicked outside of me!');
    setIsDialogOpen(false);
  }
};

Related Query

More Query from same tag