File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
packages/hooks/src/useControlled Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -271,5 +271,37 @@ describe('packages/hooks/useControlled', () => {
271271 expect ( input ) . toHaveValue ( 'carrot' ) ;
272272 } ) ;
273273 } ) ;
274+
275+ // eslint-disable-next-line jest/no-disabled-tests
276+ describe . skip ( 'types' , ( ) => {
277+ test ( 'type of `value` should be inferred from `controlledValue`' , ( ) => {
278+ {
279+ const { value } = useControlled ( 1 ) ;
280+ const _N : number = value ;
281+ // @ts -expect-error
282+ const _S : string = value ;
283+ }
284+
285+ {
286+ const { value } = useControlled ( 'hello' ) ;
287+ const _S : string = value ;
288+ // @ts -expect-error
289+ const _N : number = value ;
290+ }
291+ } ) ;
292+
293+ test ( 'controlledValue and initial value must be the same type' , ( ) => {
294+ useControlled ( 1 , ( ) => { } , 42 ) ;
295+ // @ts -expect-error
296+ useControlled ( 1 , ( ) => { } , 'foo' ) ;
297+ } ) ;
298+
299+ test ( 'type of value is inferred from `initialValue` if controlledValue is undefined' , ( ) => {
300+ const { value } = useControlled ( undefined , ( ) => { } , 42 ) ;
301+ const _N : number = value ;
302+ // @ts -expect-error
303+ const _S : string = value ;
304+ } ) ;
305+ } ) ;
274306 } ) ;
275307} ) ;
You can’t perform that action at this time.
0 commit comments