Skip to content

Commit

Permalink
Improve type accuracy for eventProps
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Apr 17, 2023
1 parent 9243e45 commit f5a9fd6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { useResolver } from './shared/hooks';
import { eventProps, isClassName, isFile, isRef } from './shared/propTypes';

import type { PDFDocumentProxy } from 'pdfjs-dist';
import type { allEvents } from 'make-event-props';
import type {
ClassName,
ExternalLinkRel,
Expand Down Expand Up @@ -73,7 +74,15 @@ type OnSourceError = OnError;

type OnSourceSuccess = () => void;

type EventProps = ReturnType<typeof makeEventProps>;
type AllEvents = (typeof allEvents)[number];

type EventHandler = (event: unknown, ...args: unknown[]) => void;

type Props = Record<string, unknown> & {
[K in AllEvents]?: EventHandler;
};

type EventProps = ReturnType<typeof makeEventProps<Props, PDFDocumentProxy>>;

type DocumentProps = {
children?: React.ReactNode;
Expand Down
11 changes: 10 additions & 1 deletion src/Outline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ import { useResolver } from './shared/hooks';
import { eventProps, isClassName, isPdf, isRef } from './shared/propTypes';

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

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

type EventProps = ReturnType<typeof makeEventProps>;
type AllEvents = (typeof allEvents)[number];

type EventHandler = (event: unknown, ...args: unknown[]) => void;

type Props = Record<string, unknown> & {
[K in AllEvents]?: EventHandler;
};

type EventProps = ReturnType<typeof makeEventProps<Props, PDFOutline | null>>;

type OutlineProps = {
className?: string;
Expand Down
12 changes: 11 additions & 1 deletion src/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from './shared/propTypes';

import type { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
import type { allEvents } from 'make-event-props';
import type {
CustomTextRenderer,
NodeOrRenderer,
Expand All @@ -46,12 +47,21 @@ import type {
OnRenderSuccess,
OnRenderTextLayerError,
OnRenderTextLayerSuccess,
PageCallback,
RenderMode,
} from './shared/types';

const defaultScale = 1;

type EventProps = ReturnType<typeof makeEventProps>;
type AllEvents = (typeof allEvents)[number];

type EventHandler = (event: unknown, ...args: unknown[]) => void;

type Props = Record<string, unknown> & {
[K in AllEvents]?: EventHandler;
};

type EventProps = ReturnType<typeof makeEventProps<Props, PageCallback>>;

type PageProps = {
canvasBackground?: string;
Expand Down

0 comments on commit f5a9fd6

Please sign in to comment.