From: Carlos Rodrigues Date: Fri, 3 Nov 2023 16:01:56 +0000 (+0000) Subject: chore: add passive + combinations X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fpikax%2Fcapture_jsx_events;p=thirdparty%2Fvuejs%2Fcore.git chore: add passive + combinations --- diff --git a/packages/dts-test/tsx.test-d.tsx b/packages/dts-test/tsx.test-d.tsx index 56f8d2f73b..3432fdc1f2 100644 --- a/packages/dts-test/tsx.test-d.tsx +++ b/packages/dts-test/tsx.test-d.tsx @@ -42,6 +42,22 @@ expectType( onInputCaptureOnce={e => { expectType(e.target) }} + onInputPassive={e => { + // infer correct event type + expectType(e.target) + }} + onInputCapturePassive={e => { + expectType(e.target) + }} + onInputOncePassive={e => { + expectType(e.target) + }} + onInputOnceCapturePassive={e => { + expectType(e.target) + }} + onInputPassiveCaptureOnce={e => { + expectType(e.target) + }} /> ) diff --git a/packages/runtime-dom/src/jsx.ts b/packages/runtime-dom/src/jsx.ts index 3de0667238..790e84dc31 100644 --- a/packages/runtime-dom/src/jsx.ts +++ b/packages/runtime-dom/src/jsx.ts @@ -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]