Преглед изворни кода

chore: add passive + combinations

Carlos Rodrigues пре 2 година
родитељ
комит
e76bcfadd8
2 измењених фајлова са 34 додато и 1 уклоњено
  1. 16 0
      packages/dts-test/tsx.test-d.tsx
  2. 18 1
      packages/runtime-dom/src/jsx.ts

+ 16 - 0
packages/dts-test/tsx.test-d.tsx

@@ -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)
+    }}
   />
 )
 

+ 18 - 1
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]