@@ -11,6 +11,7 @@ import { isHostElement } from './helpers/component-tree';
1111import { isHostTextInput } from './helpers/host-component-names' ;
1212import { isPointerEventEnabled } from './helpers/pointer-events' ;
1313import { isTextInputEditable } from './helpers/text-input' ;
14+ import { StringWithAutocomplete } from './types' ;
1415
1516type EventHandler = ( ...args : unknown [ ] ) => unknown ;
1617
@@ -105,20 +106,17 @@ function getEventHandlerName(eventName: string) {
105106 return `on${ eventName . charAt ( 0 ) . toUpperCase ( ) } ${ eventName . slice ( 1 ) } ` ;
106107}
107108
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 {
113111 [ K in keyof T as K extends `on${infer Rest } ` ? Uncapitalize < Rest > : never ] : T [ K ] ;
114112} ;
115113
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 >
122120> ;
123121
124122function fireEvent ( element : ReactTestInstance , eventName : EventName , ...data : unknown [ ] ) {
0 commit comments