I'm trying to make a type-helper where a known type can be inserted as a type parameter, and it's guaranteed to be correct. This way I can write EventHandler<MouseEvent> where I know that a MouseEvent will be the argument, and have the helper expand to (e: MouseEvent) => any for my convenience. See https://github.com/sdegutis/imlib/commit/f6a75a2c58bd4d8b5d134d446297b6fdbbbfb50d
Given
type Fn = <T extends Event>(e: T) => any;
const fn: Fn = (e: MouseEvent) => 3;
I get the error:
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)
But why? Shouldn't MouseEvent satisfy Event?
Fncan call it with aKeyboardEventand then your implementation offnmight implode (of course, not if it just returns3) as shown here. I don't know what you're trying to do, but maybe you want the type parameter to be on the type and not the call signature as shown here? Does that fully address the question? Or am I missing something?