Skip to content

Commit 9efe054

Browse files
authored
[react] Types for useSwipeTransition (DefinitelyTyped#71962)
1 parent 19f5ef5 commit 9efe054

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

types/react-dom/experimental.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ declare module "react" {
4242
old: Animatable;
4343
new: Animatable;
4444
}
45+
46+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
47+
interface GestureProvider extends AnimationTimeline {}
4548
}

types/react-dom/test/experimental-tests.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,18 @@ function viewTransitionTests() {
2727
<div />
2828
</ViewTransition>;
2929
}
30+
31+
function swipeTransitionTest() {
32+
const useSwipeTransition = React.unstable_useSwipeTransition;
33+
// $ExpectType [value: string | null, startGesture: StartGesture]
34+
const [value, startGesture] = useSwipeTransition("/?a", null, "/?b");
35+
36+
// lib.dom.d.ts has no types for ScrollTimeline yet.
37+
// $ExpectType () => void
38+
startGesture(new AnimationTimeline());
39+
const gestureProvider: {} = {};
40+
// @ts-expect-error -- Incorrect gesture provider
41+
startGesture(gestureProvider);
42+
// @ts-expect-error -- missing gesture provider
43+
startGesture();
44+
}

types/react/experimental.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,18 @@ declare module "." {
195195
* @see {@link https://github.com/facebook/react/pull/31975}
196196
*/
197197
export const unstable_ViewTransition: ExoticComponent<ViewTransitionProps>;
198+
199+
// Implemented by the specific renderer e.g. `react-dom`.
200+
// Keep in mind that augmented interfaces merge their JSDoc so if you put
201+
// JSDoc here and in the renderer, the IDE will display both.
202+
export interface GestureProvider {}
203+
204+
export type StartGesture = (gestureProvider: GestureProvider) => () => void;
205+
206+
/** */
207+
export function unstable_useSwipeTransition<Value>(
208+
previous: Value,
209+
current: Value,
210+
next: Value,
211+
): [value: Value, startGesture: StartGesture];
198212
}

types/react/test/experimental.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,15 @@ function viewTransitionTests() {
199199
<Div />
200200
</ViewTransition>;
201201
}
202+
203+
function swipeTransitionTest() {
204+
const useSwipeTransition = React.unstable_useSwipeTransition;
205+
// $ExpectType [value: string | null, startGesture: StartGesture]
206+
const [value, startGesture] = useSwipeTransition("/?a", null, "/?b");
207+
208+
const gestureProvider: {} = {};
209+
// $ExpectType () => void
210+
startGesture(gestureProvider);
211+
// @ts-expect-error -- missing gesture provider
212+
startGesture();
213+
}

types/react/ts5.0/experimental.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,18 @@ declare module "." {
195195
* @see {@link https://github.com/facebook/react/pull/31975}
196196
*/
197197
export const unstable_ViewTransition: ExoticComponent<ViewTransitionProps>;
198+
199+
// Implemented by the specific renderer e.g. `react-dom`.
200+
// Keep in mind that augmented interfaces merge their JSDoc so if you put
201+
// JSDoc here and in the renderer, the IDE will display both.
202+
export interface GestureProvider {}
203+
204+
export type StartGesture = (gestureProvider: GestureProvider) => () => void;
205+
206+
/** */
207+
export function unstable_useSwipeTransition<Value>(
208+
previous: Value,
209+
current: Value,
210+
next: Value,
211+
): [value: Value, startGesture: StartGesture];
198212
}

types/react/ts5.0/test/experimental.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,15 @@ function viewTransitionTests() {
202202
<Div />
203203
</ViewTransition>;
204204
}
205+
206+
function swipeTransitionTest() {
207+
const useSwipeTransition = React.unstable_useSwipeTransition;
208+
// $ExpectType [value: string | null, startGesture: StartGesture]
209+
const [value, startGesture] = useSwipeTransition("/?a", null, "/?b");
210+
211+
const gestureProvider: {} = {};
212+
// $ExpectType () => void
213+
startGesture(gestureProvider);
214+
// @ts-expect-error -- missing gesture provider
215+
startGesture();
216+
}

0 commit comments

Comments
 (0)