@@ -11,6 +11,7 @@ import { isHostElement } from './helpers/component-tree';
11
11
import { isHostTextInput } from './helpers/host-component-names' ;
12
12
import { isPointerEventEnabled } from './helpers/pointer-events' ;
13
13
import { isTextInputEditable } from './helpers/text-input' ;
14
+ import { StringWithAutocomplete } from './types' ;
14
15
15
16
type EventHandler = ( ...args : unknown [ ] ) => unknown ;
16
17
@@ -105,20 +106,17 @@ function getEventHandlerName(eventName: string) {
105
106
return `on${ eventName . charAt ( 0 ) . toUpperCase ( ) } ${ eventName . slice ( 1 ) } ` ;
106
107
}
107
108
108
- // Allows any string but will provide autocomplete for type T
109
- type StringWithAutoComplete < T > = T | ( string & Record < never , never > ) ;
110
-
111
- // String union type of keys of T that start with on, stripped from on
112
- type OnKeys < T > = keyof {
109
+ // String union type of keys of T that start with on, stripped of 'on'
110
+ type EventNameExtractor < T > = keyof {
113
111
[ K in keyof T as K extends `on${infer Rest } ` ? Uncapitalize < Rest > : never ] : T [ K ] ;
114
112
} ;
115
113
116
- type EventName = StringWithAutoComplete <
117
- | OnKeys < ViewProps >
118
- | OnKeys < TextProps >
119
- | OnKeys < TextInputProps >
120
- | OnKeys < PressableProps >
121
- | OnKeys < ScrollViewProps >
114
+ type EventName = StringWithAutocomplete <
115
+ | EventNameExtractor < ViewProps >
116
+ | EventNameExtractor < TextProps >
117
+ | EventNameExtractor < TextInputProps >
118
+ | EventNameExtractor < PressableProps >
119
+ | EventNameExtractor < ScrollViewProps >
122
120
> ;
123
121
124
122
function fireEvent ( element : ReactTestInstance , eventName : EventName , ...data : unknown [ ] ) {
0 commit comments