Given
<code>type Fn = <T extends Event>(e: T) => any;
const fn: Fn = (e: MouseEvent) => 3;
</code>
<code>type Fn = <T extends Event>(e: T) => any;
const fn: Fn = (e: MouseEvent) => 3;
</code>
type Fn = <T extends Event>(e: T) => any;
const fn: Fn = (e: MouseEvent) => 3;
I get the error:
<code>Type '(e: MouseEvent) => number' is not assignable to type 'Fn'.
Types of parameters 'e' and 'e' are incompatible.
Type 'T' is not assignable to type 'MouseEvent'.
Type 'Event' is missing the following properties from type 'MouseEvent': altKey, button, buttons, clientX, and 23 more.(2322)
</code>
<code>Type '(e: MouseEvent) => number' is not assignable to type 'Fn'.
Types of parameters 'e' and 'e' are incompatible.
Type 'T' is not assignable to type 'MouseEvent'.
Type 'Event' is missing the following properties from type 'MouseEvent': altKey, button, buttons, clientX, and 23 more.(2322)
</code>
Type '(e: MouseEvent) => number' is not assignable to type 'Fn'.
Types of parameters 'e' and 'e' are incompatible.
Type 'T' is not assignable to type 'MouseEvent'.
Type 'Event' is missing the following properties from type 'MouseEvent': altKey, button, buttons, clientX, and 23 more.(2322)
Playground link
But why? Shouldn’t MouseEvent satisfy Event?
New contributor
Steven is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1