I have types like this where I overwrite single type while extending interface:
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
interface HTMLEvent<T> extends Omit<Event, 'target'> {
target: T;
}
and now I want to create type EventType that will accept Event type for instance MouseEvent and target type.
I've tried this:
interface EventType<E, T> extends Omit<E, 'target'> {
target: T;
}
const e: EventType<MouseEvent, HTMLButtonElement>;
but got error:
An interface can only extend an object type or intersection of object types with statically known members.
I think what I need is a function that will create a type.
Is interface EventType possible in TypeScript? Is it possible to have one generic type without the need to specify generic interface for each event type.