Skip to content

Commit 588c3ac

Browse files
authored
Merge pull request #451 from wellyshen/fix/animate-type
Fix(types): change the type of `keyframe` option to required
2 parents 877cb1d + 769a659 commit 588c3ac

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/__tests__/useWebAnimations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("useWebAnimations", () => {
2323
keyframes = mockKeyframes,
2424
animationOptions = mockTiming,
2525
...rest
26-
}: Options<HTMLDivElement> = {}) =>
26+
}: Partial<Options<HTMLDivElement>> = {}) =>
2727
renderHook(() =>
2828
useWebAnimations({ ref, keyframes, animationOptions, ...rest })
2929
);

src/use-web-animations.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ declare module "@wellyshen/use-web-animations" {
55

66
export type PlayState = string | null;
77

8-
interface AnimConf {
9-
id?: string;
10-
playbackRate?: number;
11-
autoPlay?: boolean;
12-
animationOptions?:
8+
type AnimConf = Partial<{
9+
id: string;
10+
playbackRate: number;
11+
autoPlay: boolean;
12+
animationOptions:
1313
| number
1414
| (KeyframeAnimationOptions & { pseudoElement?: string });
15-
}
15+
}>;
1616

1717
export interface Animate {
1818
(args: AnimConf & { keyframes: Keyframes }): void;
@@ -30,7 +30,7 @@ declare module "@wellyshen/use-web-animations" {
3030

3131
export interface Options<T> extends AnimConf {
3232
ref?: RefObject<T>;
33-
keyframes?: Keyframes;
33+
keyframes: Keyframes;
3434
onReady?: Callback;
3535
onUpdate?: Callback;
3636
onFinish?: Callback;

src/useWebAnimations.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export const eventErr = (type: string): string =>
1010

1111
type Keyframes = Keyframe[] | PropertyIndexedKeyframes;
1212
type PlayState = string | null;
13-
interface AnimConf {
14-
id?: string;
15-
playbackRate?: number;
16-
autoPlay?: boolean;
17-
animationOptions?:
13+
type AnimConf = Partial<{
14+
id: string;
15+
playbackRate: number;
16+
autoPlay: boolean;
17+
animationOptions:
1818
| number
1919
| (KeyframeAnimationOptions & { pseudoElement?: string });
20-
}
20+
}>;
2121
interface Animate {
2222
(args: AnimConf & { keyframes: Keyframes }): void;
2323
}
@@ -30,7 +30,7 @@ interface Callback {
3030
}
3131
export interface Options<T> extends AnimConf {
3232
ref?: RefObject<T>;
33-
keyframes?: Keyframes;
33+
keyframes: Keyframes;
3434
onReady?: Callback;
3535
onUpdate?: Callback;
3636
onFinish?: Callback;
@@ -52,7 +52,7 @@ const useWebAnimations = <T extends HTMLElement>({
5252
onReady,
5353
onUpdate,
5454
onFinish,
55-
}: Options<T> = {}): Return<T> => {
55+
}: Options<T>): Return<T> => {
5656
const [playState, setPlayState] = useState<PlayState>(null);
5757
const hasUnmountedRef = useRef(false);
5858
const animRef = useRef<Animation>();
@@ -122,7 +122,6 @@ const useWebAnimations = <T extends HTMLElement>({
122122
);
123123

124124
useDeepCompareEffect(() => {
125-
// @ts-expect-error
126125
animate({ id, playbackRate, autoPlay, keyframes, animationOptions });
127126
}, [id, playbackRate, autoPlay, keyframes, animationOptions, animate]);
128127

0 commit comments

Comments
 (0)