The problem is that EventTraget might contain either an instance of an Element, Document or Window where the latter doesn't have a contains method.
You can tackle it by checking that your EventTarget isn't window and casting your type to Element, i.e (!textAreaRef?.current?.contains(event.target as Element)) { ...
withWith some aesthetics added, this could look something like:
const { target } = event; if(target !== window) { // or !!target.contains to check for the presence of the method const containsTarget = textAreaRef?.current?.contains(target as Element); if(containsTarget) { dispatch({type: <MY-ACTION>}); } }