While reading through the TypeScript types for React, I saw a few usages of this pattern involving a bivarianceHack()
function declaration:
type EventHandler<E extends SyntheticEvent<any>> = { bivarianceHack(event: E): void }["bivarianceHack"];
Searching didn't lead me to any documentation on why this particular pattern was used, although I've found other instances of this pattern in use so it seems it's not a React-specific pattern.
Why is this pattern being used rather than (event: E) => void
?