chore: add passive + combinations

This commit is contained in:
Carlos Rodrigues 2023-11-03 16:01:56 +00:00
parent 972a791b7e
commit e76bcfadd8
2 changed files with 34 additions and 1 deletions

View File

@ -42,6 +42,22 @@ expectType<JSX.Element>(
onInputCaptureOnce={e => {
expectType<EventTarget | null>(e.target)
}}
onInputPassive={e => {
// infer correct event type
expectType<EventTarget | null>(e.target)
}}
onInputCapturePassive={e => {
expectType<EventTarget | null>(e.target)
}}
onInputOncePassive={e => {
expectType<EventTarget | null>(e.target)
}}
onInputOnceCapturePassive={e => {
expectType<EventTarget | null>(e.target)
}}
onInputPassiveCaptureOnce={e => {
expectType<EventTarget | null>(e.target)
}}
/>
)

View File

@ -1351,7 +1351,24 @@ export interface BaseEvents {
onTransitionstart: TransitionEvent
}
type EventModifiers = 'Capture' | 'Once' | `OnceCapture` | 'CaptureOnce'
// All possible combinations, could be generated programmatically but
// probably too much trouble for little gain, especially it will incur more overhead on the typing
type EventModifiers =
| 'Capture'
| 'Once'
| 'Passive'
| 'CaptureOnce'
| 'OnceCapture'
| 'CapturePassive'
| 'PassiveCapture'
| 'OncePassive'
| 'PassiveOnce'
| 'CaptureOncePassive'
| 'CapturePassiveOnce'
| 'OnceCapturePassive'
| 'OncePassiveCapture'
| 'PassiveCaptureOnce'
| 'PassiveOnceCapture'
type Events = BaseEvents & {
[K in keyof BaseEvents as `${K & string}${EventModifiers}`]: BaseEvents[K]