File tree 2 files changed +29
-0
lines changed 2 files changed +29
-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,32 @@ const everyHookRef = React.createRef<{ id: number }>();
263
263
} } /> ;
264
264
265
265
function useExperimentalHooks ( ) {
266
+ // Implicit any
267
+ const anyEvent = React . experimental_useEvent ( value => {
268
+ // $ExpectType any
269
+ return value ;
270
+ } ) ;
271
+ // $ExpectType any
272
+ anyEvent ( { } ) ;
273
+ // $ExpectType (value: string) => number
274
+ const typedEvent = React . experimental_useEvent ( ( value : string ) => {
275
+ return Number ( value ) ;
276
+ } ) ;
277
+ // $ExpectType number
278
+ typedEvent ( '1' ) ;
279
+ // Argument of type '{}' is not assignable to parameter of type 'string'.
280
+ // @ts -expect-error
281
+ typedEvent ( { } ) ;
282
+
283
+ function useContextuallyTypedEvent ( fn : ( event : Event ) => string ) { }
284
+ useContextuallyTypedEvent (
285
+ React . experimental_useEvent ( event => {
286
+ // $ExpectType Event
287
+ event ;
288
+ return String ( event ) ;
289
+ } ) ,
290
+ ) ;
291
+
266
292
const [ toggle , setToggle ] = React . useState ( false ) ;
267
293
268
294
const [ done , startTransition ] = React . useTransition ( ) ;
You can’t perform that action at this time.
0 commit comments