Skip to content

Commit d8b74ca

Browse files
committed
test: fix expected types
Note: After this commit, there are still a few incorrect expectations in the type tests.
1 parent 290a404 commit d8b74ca

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

targets/web/src/types/__tests__/Spring.tsx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { assert, test, _ } from 'spec.ts';
33
import { animated, Spring } from '../..';
44
import { AnimationResult, SpringValues, SpringUpdateFn } from 'core';
5+
import { UnknownPartial } from 'shared';
56

67
const View = animated('div');
78

@@ -10,14 +11,17 @@ test('basic usage', () => {
1011
from={{ opacity: 0 }}
1112
to={{ opacity: 1, color: 'blue' }}
1213
onRest={result => {
13-
assert(result, _ as AnimationResult<unknown>);
14+
assert(result, _ as Readonly<AnimationResult<UnknownPartial>>);
1415
}}>
1516
{values => {
16-
assert(values, _ as SpringValues<{
17-
// FIXME: should include these
18-
// opacity: number;
19-
// color?: string;
20-
}>);
17+
assert(
18+
values,
19+
_ as SpringValues<{
20+
// FIXME: should include these
21+
// opacity: number;
22+
// color?: string;
23+
}>
24+
);
2125
return <View style={values} />;
2226
}}
2327
</Spring>;
@@ -27,16 +31,22 @@ test('async "to" prop', () => {
2731
<Spring
2832
from={{ opacity: 0 }}
2933
to={async next => {
30-
assert(next, _ as SpringUpdateFn<{
31-
// FIXME: should include this
32-
// opacity: number;
33-
}>);
34+
assert(
35+
next,
36+
_ as SpringUpdateFn<{
37+
// FIXME: should include this
38+
// opacity: number;
39+
}>
40+
);
3441
}}>
3542
{values => {
36-
assert(values, _ as SpringValues<{
37-
// FIXME: should include this
38-
// opacity: number;
39-
}>);
43+
assert(
44+
values,
45+
_ as SpringValues<{
46+
// FIXME: should include this
47+
// opacity: number;
48+
}>
49+
);
4050
return <View style={values} />;
4151
}}
4252
</Spring>;

targets/web/src/types/__tests__/useSpring.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ test('infer animated array', () => {
8383
const props = useSpring({
8484
to: { foo: [0, 0] },
8585
});
86+
assert(props.foo, _ as number[]);
8687
assert(
8788
props,
8889
_ as SpringValues<{
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { assert, test, _ } from 'spec.ts';
22
import { useSprings, SpringStopFn } from '../..';
3-
import { Controller, ControllerProps } from 'core';
43
import {
4+
Controller,
5+
ControllerProps,
56
SpringsUpdateFn,
67
SpringValues,
7-
} from '@react-spring/core/src/types/spring';
8+
} from 'core';
89

910
const items: string[] = [];
1011

12+
type State = { opacity: number };
13+
1114
test('pass an array', () => {
1215
const springs = useSprings(
1316
items.length,
@@ -16,29 +19,23 @@ test('pass an array', () => {
1619
return { opacity: 1 / Number(item) };
1720
})
1821
);
19-
assert(springs, _ as Array<
20-
SpringValues<{
21-
opacity: number;
22-
}>
23-
>);
22+
assert(springs, _ as Array<SpringValues<State>>);
2423
});
2524

2625
test('pass a function', () => {
2726
const [springs, set, stop] = useSprings(2, i => {
2827
assert(i, _ as number);
2928
return { opacity: i };
3029
});
31-
type State = { opacity: number };
32-
assert(springs, _ as Array<
33-
SpringValues<{
34-
opacity: number;
35-
}>
36-
>);
30+
31+
assert(springs, _ as Array<SpringValues<State>>);
32+
3733
set({ opacity: 1 });
3834
set([{ opacity: 1 }, { opacity: 0.5 }]);
39-
set((_index: number, _spring: Controller<{ opacity: number }>) => {
40-
return _ as ControllerProps<{ opacity?: number }>;
35+
set((_index: number, _spring: Controller<State>) => {
36+
return _ as ControllerProps<State>;
4137
});
38+
4239
assert(set, _ as SpringsUpdateFn<State>);
4340
assert(stop, _ as SpringStopFn<State>);
4441
});

0 commit comments

Comments
 (0)