44 * This source code is licensed under the MIT license found in the
55 * LICENSE file in the root directory of this source tree.
66 *
7- * @flow
7+ * @flow strict-local
88 * @format
99 * @deprecated
1010 */
@@ -29,13 +29,15 @@ export type JSTimerType =
2929 | 'queueReactNativeMicrotask'
3030 | 'requestIdleCallback' ;
3131
32+ type TimerFunc = ( ...args : Array < unknown > ) => unknown ;
33+
3234// These timing constants should be kept in sync with the ones in native ios and
3335// android `RCTTiming` module.
3436const FRAME_DURATION = 1000 / 60 ;
3537const IDLE_CALLBACK_FRAME_DEADLINE = 1 ;
3638
3739// Parallel arrays
38- const callbacks : Array < ?Function > = [ ] ;
40+ const callbacks : Array < ?TimerFunc > = [ ] ;
3941const types : Array < ?JSTimerType > = [ ] ;
4042const timerIDs : Array < ?number > = [ ] ;
4143const freeIdxs : Array < number > = [];
@@ -57,7 +59,7 @@ function _getFreeIndex(): number {
5759 return freeIdx ;
5860}
5961
60- function _allocateCallback(func: Function , type: JSTimerType): number {
62+ function _allocateCallback(func: TimerFunc , type: JSTimerType): number {
6163 const id = GUID ++ ;
6264 const freeIndex = _getFreeIndex ( ) ;
6365 timerIDs [ freeIndex ] = id ;
@@ -210,9 +212,9 @@ const JSTimers = {
210212 * @param {number } duration Number of milliseconds.
211213 */
212214 setTimeout : function (
213- func : Function ,
215+ func : TimerFunc ,
214216 duration : number ,
215- ...args : any
217+ ...args : Array < unknown >
216218 ) : number {
217219 const id = _allocateCallback (
218220 ( ) => func . apply ( undefined , args ) ,
@@ -227,9 +229,9 @@ const JSTimers = {
227229 * @param {number } duration Number of milliseconds.
228230 */
229231 setInterval : function (
230- func: Function ,
232+ func : TimerFunc ,
231233 duration : number ,
232- ...args: any
234+ ...args : Array < unknown >
233235 ) : number {
234236 const id = _allocateCallback (
235237 ( ) => func . apply ( undefined , args ) ,
@@ -247,7 +249,10 @@ const JSTimers = {
247249 * @param {function } func Callback to be invoked before the end of the
248250 * current JavaScript execution loop.
249251 */
250- queueReactNativeMicrotask: function (func: Function, ...args: any): number {
252+ queueReactNativeMicrotask : function (
253+ func : TimerFunc ,
254+ ...args : Array < unknown >
255+ ) : number {
251256 const id = _allocateCallback (
252257 ( ) => func . apply ( undefined , args ) ,
253258 'queueReactNativeMicrotask' ,
@@ -259,7 +264,7 @@ const JSTimers = {
259264 /**
260265 * @param {function } func Callback to be invoked every frame.
261266 */
262- requestAnimationFrame: function (func: Function): any | number {
267+ requestAnimationFrame : function ( func : TimerFunc ) : number {
263268 const id = _allocateCallback ( func , 'requestAnimationFrame' ) ;
264269 createTimer ( id , 1 , Date . now ( ) , /* recurring */ false ) ;
265270 return id ;
@@ -271,17 +276,17 @@ const JSTimers = {
271276 * @param {?object } options
272277 */
273278 requestIdleCallback : function (
274- func: Function ,
275- options: ?Object ,
276- ): any | number {
279+ func : TimerFunc ,
280+ options : ?{ timeout ? : number , ... } ,
281+ ) : number {
277282 if ( requestIdleCallbacks . length === 0 ) {
278283 setSendIdleEvents ( true ) ;
279284 }
280285
281286 const timeout = options && options . timeout ;
282287 const id : number = _allocateCallback (
283288 timeout != null
284- ? ( deadline : any ) => {
289+ ? ( deadline : unknown ) => {
285290 const timeoutId : number = requestIdleCallbackTimeouts [ id ] ;
286291 if ( timeoutId ) {
287292 JSTimers . clearTimeout ( timeoutId ) ;
@@ -353,7 +358,7 @@ const JSTimers = {
353358 * This is called from the native side. We are passed an array of timerIDs,
354359 * and
355360 */
356- callTimers: function (timersToCall: Array< number > ): any | void {
361+ callTimers : function ( timersToCall : Array < number > ) : void {
357362 invariant (
358363 timersToCall . length !== 0 ,
359364 'Cannot call `callTimers` with an empty list of IDs.' ,
@@ -458,20 +463,34 @@ function setSendIdleEvents(sendIdleEvents: boolean): void {
458463}
459464
460465let ExportedJSTimers : {
461- callIdleCallbacks : ( frameTime : number ) = > any | void ,
466+ callIdleCallbacks : ( frameTime : number ) = > void ,
462467 callReactNativeMicrotasks : ( ) = > void ,
463- callTimers : ( timersToCall : Array < number > ) => any | void ,
468+ callTimers : ( timersToCall : Array < number > ) => void ,
464469 cancelAnimationFrame : ( timerID : number ) = > void ,
465470 cancelIdleCallback : ( timerID : number ) = > void ,
466471 clearReactNativeMicrotask : ( timerID : number ) = > void ,
467472 clearInterval : ( timerID : number ) = > void ,
468473 clearTimeout : ( timerID : number ) = > void ,
469- emitTimeDriftWarning : ( warningMessage : string ) = > any | void ,
470- requestAnimationFrame : ( func : any ) = > any | number ,
471- requestIdleCallback : ( func : any , options : ?any ) = > any | number ,
472- queueReactNativeMicrotask : ( func : any , ...args : any ) = > number ,
473- setInterval : ( func : any , duration : number , ...args : any ) = > number ,
474- setTimeout : ( func : any , duration : number , ...args : any ) = > number ,
474+ emitTimeDriftWarning : ( warningMessage : string ) = > void ,
475+ requestAnimationFrame : ( func : TimerFunc ) = > number ,
476+ requestIdleCallback : (
477+ func : TimerFunc ,
478+ options : ?{ timeout ? : number , ...} ,
479+ ) = > number ,
480+ queueReactNativeMicrotask : (
481+ func : TimerFunc ,
482+ ...args : Array < unknown >
483+ ) => number ,
484+ setInterval : (
485+ func : TimerFunc ,
486+ duration : number ,
487+ ...args : Array < unknown >
488+ ) => number ,
489+ setTimeout : (
490+ func : TimerFunc ,
491+ duration : number ,
492+ ...args : Array < unknown >
493+ ) => number ,
475494} ;
476495
477496if ( ! NativeTiming ) {
0 commit comments