File tree 2 files changed +30
-0
lines changed 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -129,4 +129,7 @@ declare module '.' {
129
129
export type Usable < T > = Thenable < T > | Context < T > ;
130
130
131
131
export function experimental_use < T > ( usable : Usable < T > ) : T ;
132
+
133
+ // tslint:disable-next-line ban-types
134
+ export function experimental_useEvent < T extends Function > ( event : T ) : T ;
132
135
}
Original file line number Diff line number Diff line change @@ -263,6 +263,33 @@ const everyHookRef = React.createRef<{ id: number }>();
263
263
} } /> ;
264
264
265
265
function useExperimentalHooks ( ) {
266
+ // Implicit any
267
+ // @ts -expect-error
268
+ const anyEvent = React . experimental_useEvent ( value => {
269
+ // $ExpectType any
270
+ return value ;
271
+ } ) ;
272
+ // $ExpectType any
273
+ anyEvent ( { } ) ;
274
+ // $ExpectType (value: string) => number
275
+ const typedEvent = React . experimental_useEvent ( ( value : string ) => {
276
+ return Number ( value ) ;
277
+ } ) ;
278
+ // $ExpectType number
279
+ typedEvent ( '1' ) ;
280
+ // Argument of type '{}' is not assignable to parameter of type 'string'.
281
+ // @ts -expect-error
282
+ typedEvent ( { } ) ;
283
+
284
+ function useContextuallyTypedEvent ( fn : ( event : Event ) => string ) { }
285
+ useContextuallyTypedEvent (
286
+ React . experimental_useEvent ( event => {
287
+ // $ExpectType Event
288
+ event ;
289
+ return String ( event ) ;
290
+ } ) ,
291
+ ) ;
292
+
266
293
const [ toggle , setToggle ] = React . useState ( false ) ;
267
294
268
295
const [ done , startTransition ] = React . useTransition ( ) ;
You can’t perform that action at this time.
0 commit comments