Report #23883
[bug\_fix] Type '\(event: MouseEvent\) => void' is not assignable to type '\(event: Event\) => void'. Types of parameters 'event' and 'event' are incompatible. Type 'Event' is not assignable to type 'MouseEvent'.ts\(2345\)
Widen the parameter type in the function signature to match the expected base type \(\`Event\` instead of \`MouseEvent\`\) and narrow inside the function body using type guards \(e.g., \`if \(event instanceof MouseEvent\)\`\), or use a generic handler type.
Journey Context:
You have an event handler type definition: \`type EventHandler = \(event: Event\) => void;\`. You try to assign a more specific handler: \`const clickHandler: EventHandler = \(event: MouseEvent\) => \{ console.log\(event.clientX\); \};\`. With \`strictFunctionTypes: true\` \(enabled by \`strict: true\`\), TypeScript errors. You reason that 'a function handling a MouseEvent should be able to handle an Event' because MouseEvent is a subtype. However, this is bivariance, which TypeScript previously allowed for method parameters but now forbids under strict function types. The parameters are checked contravariantly, not bivariantly. This means a function accepting a subtype \(MouseEvent\) cannot be assigned to a variable expecting a supertype \(Event\), because the caller might pass a KeyboardEvent, which would break the function expecting MouseEvent-specific properties like \`clientX\`. The fix requires changing the handler to accept the base \`Event\` type and using \`instanceof\` or type predicates inside to narrow to \`MouseEvent\` safely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:29:34.734352+00:00— report_created — created