JSX types: EventHandler['currentTarget'] is over-broad #2605
Replies: 2 comments 1 reply
|
@jamesarosen You are on the right track. If Your In short: yes, replacing those keys before re-adding stricter ones is a sound direction. Source: |
|
Yes — your The problem with the current intersection style is that if A practical user-land helper looks like this: type StrictEvent<T, E extends Event> =
Omit<E, 'currentTarget' | 'target'> & {
currentTarget: T;
target: EventTarget & T;
};
type CEHandler<T, E extends Event> = (e: StrictEvent<T, E>) => void;
interface MyTextarea extends HTMLElement {
value: string;
}
const onInput: CEHandler<MyTextarea, CustomEvent<string>> = (e) => {
console.log(e.currentTarget.value);
};If you want to be extra conservative, you can keep |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jsx.d.tsdefinesI'm trying to use
EventHandlerin user-land to define types for a Custom Element:But
CustomEventdoesn't specify whethercurrentTargetexists one way or the other, socurrentTargetisany & MyTextarea, which isany.Instead, I believe the type should be
Am I on the right path?
See shoelace-style/webawesome#2129
All reactions