@@ -3,6 +3,7 @@ import * as React from 'react'
33import { render } from '@testing-library/react'
44import { useSafeEffect , useSafeEffectExtraDeps } from '.'
55import { useSafeCallback } from './../use-safe-callback'
6+ import { CallbackFn } from '../use-extra-deps'
67
78describe ( 'useSafeEffect' , ( ) => {
89 it ( 'works with no deps' , async ( ) => {
@@ -71,8 +72,8 @@ describe('useSafeEffect', () => {
7172 }
7273 p2 : number
7374 } ) => {
74- useSafeEffectExtraDeps ( ( { say} ) => sideEffect ( say ) , [ ] , {
75- say : { value : p1 , comparator : ( a : { text : string } , b : { text : string } ) => a . text === b . text }
75+ useSafeEffectExtraDeps < { say : { text : string } } > ( ( { say} ) => sideEffect ( say ) , [ ] , {
76+ say : { value : p1 , comparator : ( a , b ) => a . text === b . text }
7677 } )
7778 return < > { p2 } </ >
7879 }
@@ -105,15 +106,15 @@ describe('useSafeEffect', () => {
105106 const countTrue = jest . fn ( ( arr : Array < boolean > ) : number => arr . filter ( x => x === true ) . length )
106107
107108 const C = ( { p1, p2} : { p1 : Array < boolean > ; p2 : number } ) => {
108- useSafeEffectExtraDeps (
109+ useSafeEffectExtraDeps < { p1 : boolean [ ] } > (
109110 ( { p1} ) => {
110111 // Cannot return anything except a clean-up function
111112 countTrue ( p1 )
112113 } ,
113114 [ ] ,
114115 {
115116 // Only run effect when array length changes, regardless of contents
116- p1 : { value : p1 , comparator : ( a : boolean [ ] , b : boolean [ ] ) => a . length === b . length }
117+ p1 : { value : p1 , comparator : ( a , b ) => a . length === b . length }
117118 }
118119 )
119120 return < > { p2 } </ >
@@ -160,14 +161,13 @@ describe('useSafeEffect', () => {
160161
161162 return < C p2 = { p2 } p3 = { p3 } f = { cbF } />
162163 }
163- // eslint-disable-next-line @typescript-eslint/no-explicit-any
164- const C = ( { f, p2, p3} : { f : ( v : any ) => any ; p2 : number ; p3 : number } ) => {
165- useSafeEffectExtraDeps (
164+ const C = ( { f, p2, p3} : { f : CallbackFn < ( b : number ) => void > ; p2 : number ; p3 : number } ) => {
165+ useSafeEffectExtraDeps < { p3 : number ; f : ( b : number ) => void } > (
166166 ( { p3, f} ) => {
167167 return f ( p3 )
168168 } ,
169169 [ ] ,
170- { p3 : { value : p3 , comparator : ( a : number , b : number ) => a === b } , f}
170+ { p3 : { value : p3 , comparator : ( a , b ) => a === b } , f}
171171 )
172172 return < > { p2 } </ >
173173 }
@@ -213,16 +213,16 @@ describe('useSafeEffect', () => {
213213 p3 : number
214214 p4 : boolean
215215 } ) => {
216- useSafeEffectExtraDeps (
216+ useSafeEffectExtraDeps < { p1 : { text : string } ; p2 : string [ ] } > (
217217 ( { p1, p2} ) => {
218218 // Cannot return anything except a clean-up function
219219 computation ( p1 . text , p2 , p3 , p4 )
220220 } ,
221221 [ p3 , p4 ] ,
222222 {
223- p1 : { value : p1 , comparator : ( a : { text : string } , b : { text : string } ) => a . text === b . text } ,
223+ p1 : { value : p1 , comparator : ( a , b ) => a . text === b . text } ,
224224 // Deep comparison of arrays
225- p2 : { value : p2 , comparator : ( a : string [ ] , b : string [ ] ) => isEqual ( a , b ) }
225+ p2 : { value : p2 , comparator : ( a , b ) => isEqual ( a , b ) }
226226 }
227227 )
228228 return < > { p1 . text } </ >
@@ -266,8 +266,8 @@ describe('useSafeEffect', () => {
266266 }
267267 p2 : number
268268 } ) => {
269- useSafeEffectExtraDeps ( ( { say} ) => sideEffect ( say ) , [ ] , {
270- say : { value : p1 , comparator : ( a : { text : string } , b : { text : string } ) => a . text === b . text }
269+ useSafeEffectExtraDeps < { say : { text : string } } > ( ( { say} ) => sideEffect ( say ) , [ ] , {
270+ say : { value : p1 , comparator : ( a , b ) => a . text === b . text }
271271 } )
272272 return < > { p2 } </ >
273273 }
0 commit comments