Skip to content

Commit

Permalink
fix(types): add types for ref (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeetiss authored Mar 30, 2021
1 parent af3e08a commit da02f23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, CSSProperties } from "react";
import { FC, ForwardedRef, CSSProperties } from "react";

type State = {
width?: number;
Expand Down Expand Up @@ -47,6 +47,7 @@ declare const Canvas: FC<{
frames: ImageData[];
width?: number;
height?: number;
ref?: ForwardedRef<HTMLCanvasElement>;
fit?: "cover" | "contain" | "fill";
className?: string;
style?: CSSProperties;
Expand Down
11 changes: 11 additions & 0 deletions test-d/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,16 @@ expectError(usePlayback(pstate, update));

expectType(<Canvas {...pstate} />);

const ref = React.createRef<HTMLCanvasElement>();
expectType(<Canvas {...pstate} ref={ref} />);
expectType(
<Canvas
{...pstate}
ref={(ref) => {
expectType<HTMLCanvasElement | null>(ref);
}}
/>
);

useWorkerParser("str", update);
useParser("str", update);

0 comments on commit da02f23

Please sign in to comment.