Skip to content

Commit b19f519

Browse files
committed
Add type tests
1 parent a565b3f commit b19f519

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/hooks/src/useControlled/useControlled.spec.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)