Skip to content

Commit

Permalink
[react] Types for useSwipeTransition (DefinitelyTyped#71962)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Feb 17, 2025
1 parent 19f5ef5 commit 9efe054
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions types/react-dom/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ declare module "react" {
old: Animatable;
new: Animatable;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface GestureProvider extends AnimationTimeline {}
}
15 changes: 15 additions & 0 deletions types/react-dom/test/experimental-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,18 @@ function viewTransitionTests() {
<div />
</ViewTransition>;
}

function swipeTransitionTest() {
const useSwipeTransition = React.unstable_useSwipeTransition;
// $ExpectType [value: string | null, startGesture: StartGesture]
const [value, startGesture] = useSwipeTransition("/?a", null, "/?b");

// lib.dom.d.ts has no types for ScrollTimeline yet.
// $ExpectType () => void
startGesture(new AnimationTimeline());
const gestureProvider: {} = {};
// @ts-expect-error -- Incorrect gesture provider
startGesture(gestureProvider);
// @ts-expect-error -- missing gesture provider
startGesture();
}
14 changes: 14 additions & 0 deletions types/react/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,18 @@ declare module "." {
* @see {@link https://github.com/facebook/react/pull/31975}
*/
export const unstable_ViewTransition: ExoticComponent<ViewTransitionProps>;

// Implemented by the specific renderer e.g. `react-dom`.
// Keep in mind that augmented interfaces merge their JSDoc so if you put
// JSDoc here and in the renderer, the IDE will display both.
export interface GestureProvider {}

export type StartGesture = (gestureProvider: GestureProvider) => () => void;

/** */
export function unstable_useSwipeTransition<Value>(
previous: Value,
current: Value,
next: Value,
): [value: Value, startGesture: StartGesture];
}
12 changes: 12 additions & 0 deletions types/react/test/experimental.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,15 @@ function viewTransitionTests() {
<Div />
</ViewTransition>;
}

function swipeTransitionTest() {
const useSwipeTransition = React.unstable_useSwipeTransition;
// $ExpectType [value: string | null, startGesture: StartGesture]
const [value, startGesture] = useSwipeTransition("/?a", null, "/?b");

const gestureProvider: {} = {};
// $ExpectType () => void
startGesture(gestureProvider);
// @ts-expect-error -- missing gesture provider
startGesture();
}
14 changes: 14 additions & 0 deletions types/react/ts5.0/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,18 @@ declare module "." {
* @see {@link https://github.com/facebook/react/pull/31975}
*/
export const unstable_ViewTransition: ExoticComponent<ViewTransitionProps>;

// Implemented by the specific renderer e.g. `react-dom`.
// Keep in mind that augmented interfaces merge their JSDoc so if you put
// JSDoc here and in the renderer, the IDE will display both.
export interface GestureProvider {}

export type StartGesture = (gestureProvider: GestureProvider) => () => void;

/** */
export function unstable_useSwipeTransition<Value>(
previous: Value,
current: Value,
next: Value,
): [value: Value, startGesture: StartGesture];
}
12 changes: 12 additions & 0 deletions types/react/ts5.0/test/experimental.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,15 @@ function viewTransitionTests() {
<Div />
</ViewTransition>;
}

function swipeTransitionTest() {
const useSwipeTransition = React.unstable_useSwipeTransition;
// $ExpectType [value: string | null, startGesture: StartGesture]
const [value, startGesture] = useSwipeTransition("/?a", null, "/?b");

const gestureProvider: {} = {};
// $ExpectType () => void
startGesture(gestureProvider);
// @ts-expect-error -- missing gesture provider
startGesture();
}

0 comments on commit 9efe054

Please sign in to comment.