-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSpring.test-d.tsx
More file actions
46 lines (43 loc) · 1.53 KB
/
Copy pathSpring.test-d.tsx
File metadata and controls
46 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as React from 'react'
import { it, expectTypeOf } from 'vitest'
import { SpringValue } from '../SpringValue'
import { Spring } from './Spring'
/**
* Guard for #2006 — "render prop within <Spring> is inferred to any".
*
* The render prop should be inferred from `from`/`to` as a `SpringValues`
* object (e.g. `{ opacity: SpringValue<number>, color: SpringValue<string> }`),
* not `any` (which breaks consumers under `noImplicitAny`).
*/
// `to`-based overload (state inferred from `to`).
it('#2006: <Spring to> render prop is inferred as SpringValues, not any', () => {
function scenario() {
return (
<Spring to={{ opacity: 1, color: 'blue' }}>
{styles => {
expectTypeOf(styles).not.toBeAny()
expectTypeOf(styles.opacity).toEqualTypeOf<SpringValue<number>>()
expectTypeOf(styles.color).toEqualTypeOf<SpringValue<string>>()
return null
}}
</Spring>
)
}
expectTypeOf(scenario).toBeFunction()
})
// `from`-based overload (overload 1) — the exact shape from the issue's repo.
it('#2006: <Spring from> render prop is inferred as SpringValues, not any', () => {
function scenario() {
return (
<Spring from={{ opacity: 0, color: 'red' }}>
{styles => {
expectTypeOf(styles).not.toBeAny()
expectTypeOf(styles.opacity).toEqualTypeOf<SpringValue<number>>()
expectTypeOf(styles.color).toEqualTypeOf<SpringValue<string>>()
return null
}}
</Spring>
)
}
expectTypeOf(scenario).toBeFunction()
})