@@ -123,7 +123,7 @@ describe('packages/hooks/useControlled', () => {
123123 } ) ;
124124
125125 describe ( 'Uncontrolled' , ( ) => {
126- test ( 'calling without a value sets value to `initialValue`' , ( ) => {
126+ test ( 'calling without a `controlledValue` sets value to `initialValue`' , ( ) => {
127127 const {
128128 result : { current } ,
129129 } = renderUseControlledHook ( undefined , ( ) => { } , 'apple' ) ;
@@ -274,7 +274,7 @@ describe('packages/hooks/useControlled', () => {
274274
275275 // eslint-disable-next-line jest/no-disabled-tests
276276 describe . skip ( 'types' , ( ) => {
277- test ( 'type of `value` should be inferred from `controlledValue`' , ( ) => {
277+ test ( 'type of `value` is inferred from `controlledValue`' , ( ) => {
278278 {
279279 const { value } = useControlled ( 1 ) ;
280280 const _N : number = value ;
@@ -291,17 +291,40 @@ describe('packages/hooks/useControlled', () => {
291291 } ) ;
292292
293293 test ( 'controlledValue and initial value must be the same type' , ( ) => {
294- useControlled ( 1 , ( ) => { } , 42 ) ;
294+ useControlled ( 1 , jest . fn ( ) , 42 ) ;
295295 // @ts -expect-error
296- useControlled ( 1 , ( ) => { } , 'foo' ) ;
296+ useControlled ( 1 , jest . fn ( ) , 'foo' ) ;
297297 } ) ;
298298
299299 test ( 'type of value is inferred from `initialValue` if controlledValue is undefined' , ( ) => {
300- const { value } = useControlled ( undefined , ( ) => { } , 42 ) ;
300+ const { value } = useControlled ( undefined , jest . fn ( ) , 42 ) ;
301301 const _N : number = value ;
302302 // @ts -expect-error
303303 const _S : string = value ;
304304 } ) ;
305+
306+ test ( 'type of value is `any` if no initial or controlledValue are provided' , ( ) => {
307+ const { value } = useControlled ( undefined , jest . fn ( ) ) ;
308+ const _A : any = value ;
309+ const _N : number = value ;
310+ const _S : string = value ;
311+ } ) ;
312+
313+ test ( 'value is explicitly typed if generic param is provided' , ( ) => {
314+ {
315+ const { value } = useControlled < number > ( undefined , jest . fn ( ) ) ;
316+ const _N : number = value ;
317+ // @ts -expect-error
318+ const _S : string = value ;
319+ }
320+
321+ {
322+ const { value } = useControlled < undefined > ( undefined , jest . fn ( ) ) ;
323+ const _U : undefined = value ;
324+ // @ts -expect-error
325+ const _S : string = value ;
326+ }
327+ } ) ;
305328 } ) ;
306329 } ) ;
307330} ) ;
0 commit comments