Skip to content

Commit f5a9fd6

Browse files
committed
Improve type accuracy for eventProps
1 parent 9243e45 commit f5a9fd6

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/Document.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { useResolver } from './shared/hooks';
3939
import { eventProps, isClassName, isFile, isRef } from './shared/propTypes';
4040

4141
import type { PDFDocumentProxy } from 'pdfjs-dist';
42+
import type { allEvents } from 'make-event-props';
4243
import type {
4344
ClassName,
4445
ExternalLinkRel,
@@ -73,7 +74,15 @@ type OnSourceError = OnError;
7374

7475
type OnSourceSuccess = () => void;
7576

76-
type EventProps = ReturnType<typeof makeEventProps>;
77+
type AllEvents = (typeof allEvents)[number];
78+
79+
type EventHandler = (event: unknown, ...args: unknown[]) => void;
80+
81+
type Props = Record<string, unknown> & {
82+
[K in AllEvents]?: EventHandler;
83+
};
84+
85+
type EventProps = ReturnType<typeof makeEventProps<Props, PDFDocumentProxy>>;
7786

7887
type DocumentProps = {
7988
children?: React.ReactNode;

src/Outline.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ import { useResolver } from './shared/hooks';
1717
import { eventProps, isClassName, isPdf, isRef } from './shared/propTypes';
1818

1919
import type { PDFDocumentProxy } from 'pdfjs-dist';
20+
import type { allEvents } from 'make-event-props';
2021
import type { OnItemClickArgs } from './shared/types';
2122

2223
type PDFOutline = Awaited<ReturnType<PDFDocumentProxy['getOutline']>>;
2324

24-
type EventProps = ReturnType<typeof makeEventProps>;
25+
type AllEvents = (typeof allEvents)[number];
26+
27+
type EventHandler = (event: unknown, ...args: unknown[]) => void;
28+
29+
type Props = Record<string, unknown> & {
30+
[K in AllEvents]?: EventHandler;
31+
};
32+
33+
type EventProps = ReturnType<typeof makeEventProps<Props, PDFOutline | null>>;
2534

2635
type OutlineProps = {
2736
className?: string;

src/Page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from './shared/propTypes';
3232

3333
import type { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
34+
import type { allEvents } from 'make-event-props';
3435
import type {
3536
CustomTextRenderer,
3637
NodeOrRenderer,
@@ -46,12 +47,21 @@ import type {
4647
OnRenderSuccess,
4748
OnRenderTextLayerError,
4849
OnRenderTextLayerSuccess,
50+
PageCallback,
4951
RenderMode,
5052
} from './shared/types';
5153

5254
const defaultScale = 1;
5355

54-
type EventProps = ReturnType<typeof makeEventProps>;
56+
type AllEvents = (typeof allEvents)[number];
57+
58+
type EventHandler = (event: unknown, ...args: unknown[]) => void;
59+
60+
type Props = Record<string, unknown> & {
61+
[K in AllEvents]?: EventHandler;
62+
};
63+
64+
type EventProps = ReturnType<typeof makeEventProps<Props, PageCallback>>;
5565

5666
type PageProps = {
5767
canvasBackground?: string;

0 commit comments

Comments
 (0)