Skip to content

Commit dbc1e4b

Browse files
committed
Add explicit function return types
1 parent 4291619 commit dbc1e4b

22 files changed

+62
-46
lines changed

packages/react-pdf/src/Document.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function isParameterObject(file: File): file is Source {
232232
/**
233233
* Loads a document passed using `file` prop.
234234
*/
235-
const Document = forwardRef(function Document(
235+
const Document: React.ForwardRefExoticComponent<DocumentProps> = forwardRef(function Document(
236236
{
237237
children,
238238
className,
@@ -255,7 +255,7 @@ const Document = forwardRef(function Document(
255255
renderMode,
256256
rotate,
257257
...otherProps
258-
}: DocumentProps,
258+
},
259259
ref,
260260
) {
261261
const [sourceState, sourceDispatch] = useResolver<Source | null>();

packages/react-pdf/src/DocumentContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ import { createContext } from 'react';
44

55
import type { DocumentContextType } from './shared/types.js';
66

7-
export default createContext<DocumentContextType>(null);
7+
const documentContext: React.Context<DocumentContextType> =
8+
createContext<DocumentContextType>(null);
9+
10+
export default documentContext;

packages/react-pdf/src/LinkService.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,31 @@ export default class LinkService implements IPDFLinkService {
4949
this.pdfViewer = undefined;
5050
}
5151

52-
setDocument(pdfDocument: PDFDocumentProxy) {
52+
setDocument(pdfDocument: PDFDocumentProxy): void {
5353
this.pdfDocument = pdfDocument;
5454
}
5555

56-
setViewer(pdfViewer: PDFViewer) {
56+
setViewer(pdfViewer: PDFViewer): void {
5757
this.pdfViewer = pdfViewer;
5858
}
5959

60-
setExternalLinkRel(externalLinkRel?: ExternalLinkRel) {
60+
setExternalLinkRel(externalLinkRel?: ExternalLinkRel): void {
6161
this.externalLinkRel = externalLinkRel;
6262
}
6363

64-
setExternalLinkTarget(externalLinkTarget?: ExternalLinkTarget) {
64+
setExternalLinkTarget(externalLinkTarget?: ExternalLinkTarget): void {
6565
this.externalLinkTarget = externalLinkTarget;
6666
}
6767

68-
setHistory() {
68+
setHistory(): void {
6969
// Intentionally empty
7070
}
7171

72-
get pagesCount() {
72+
get pagesCount(): number {
7373
return this.pdfDocument ? this.pdfDocument.numPages : 0;
7474
}
7575

76-
get page() {
76+
get page(): number {
7777
invariant(this.pdfViewer, 'PDF viewer is not initialized.');
7878

7979
return this.pdfViewer.currentPageNumber || 0;
@@ -85,7 +85,7 @@ export default class LinkService implements IPDFLinkService {
8585
this.pdfViewer.currentPageNumber = value;
8686
}
8787

88-
get rotation() {
88+
get rotation(): number {
8989
return 0;
9090
}
9191

@@ -147,11 +147,11 @@ export default class LinkService implements IPDFLinkService {
147147
});
148148
}
149149

150-
navigateTo(dest: Dest) {
150+
navigateTo(dest: Dest): void {
151151
this.goToDestination(dest);
152152
}
153153

154-
goToPage(pageNumber: number) {
154+
goToPage(pageNumber: number): void {
155155
const pageIndex = pageNumber - 1;
156156

157157
invariant(this.pdfViewer, 'PDF viewer is not initialized.');
@@ -167,41 +167,41 @@ export default class LinkService implements IPDFLinkService {
167167
});
168168
}
169169

170-
addLinkAttributes(link: HTMLAnchorElement, url: string, newWindow: boolean) {
170+
addLinkAttributes(link: HTMLAnchorElement, url: string, newWindow: boolean): void {
171171
link.href = url;
172172
link.rel = this.externalLinkRel || DEFAULT_LINK_REL;
173173
link.target = newWindow ? '_blank' : this.externalLinkTarget || '';
174174
}
175175

176-
getDestinationHash() {
176+
getDestinationHash(): string {
177177
return '#';
178178
}
179179

180-
getAnchorUrl() {
180+
getAnchorUrl(): string {
181181
return '#';
182182
}
183183

184-
setHash() {
184+
setHash(): void {
185185
// Intentionally empty
186186
}
187187

188-
executeNamedAction() {
188+
executeNamedAction(): void {
189189
// Intentionally empty
190190
}
191191

192-
cachePageRef() {
192+
cachePageRef(): void {
193193
// Intentionally empty
194194
}
195195

196-
isPageVisible() {
196+
isPageVisible(): boolean {
197197
return true;
198198
}
199199

200-
isPageCached() {
200+
isPageCached(): boolean {
201201
return true;
202202
}
203203

204-
executeSetOCGState() {
204+
executeSetOCGState(): void {
205205
// Intentionally empty
206206
}
207207
}

packages/react-pdf/src/Message.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ type MessageProps = {
33
type: 'error' | 'loading' | 'no-data';
44
};
55

6-
export default function Message({ children, type }: MessageProps) {
6+
export default function Message({ children, type }: MessageProps): React.ReactElement {
77
return <div className={`react-pdf__message react-pdf__message--${type}`}>{children}</div>;
88
}

packages/react-pdf/src/Outline.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export type OutlineProps = {
6464
*
6565
* Should be placed inside `<Document />`. Alternatively, it can have `pdf` prop passed, which can be obtained from `<Document />`'s `onLoadSuccess` callback function.
6666
*/
67-
export default function Outline(props: OutlineProps) {
67+
export default function Outline(props: OutlineProps): React.ReactNode {
6868
const documentContext = useDocumentContext();
6969

7070
const mergedProps = { ...documentContext, ...props };

packages/react-pdf/src/OutlineContext.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ import { createContext } from 'react';
44

55
import type { OutlineContextType } from './shared/types.js';
66

7-
export default createContext<OutlineContextType>(null);
7+
const outlineContext: React.Context<OutlineContextType> = createContext<OutlineContextType>(null);
8+
9+
export default outlineContext;

packages/react-pdf/src/OutlineItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type OutlineItemProps = {
1818
pdf?: PDFDocumentProxy | false;
1919
};
2020

21-
export default function OutlineItem(props: OutlineItemProps) {
21+
export default function OutlineItem(props: OutlineItemProps): React.ReactElement {
2222
const documentContext = useDocumentContext();
2323

2424
const outlineContext = useOutlineContext();

packages/react-pdf/src/Page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export type PageProps = {
300300
*
301301
* Should be placed inside `<Document />`. Alternatively, it can have `pdf` prop passed, which can be obtained from `<Document />`'s `onLoadSuccess` callback function, however some advanced functions like linking between pages inside a document may not be working correctly.
302302
*/
303-
export default function Page(props: PageProps) {
303+
export default function Page(props: PageProps): React.ReactElement {
304304
const documentContext = useDocumentContext();
305305

306306
const mergedProps = { ...documentContext, ...props };

packages/react-pdf/src/Page/AnnotationLayer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { cancelRunningTask } from '../shared/utils.js';
1414

1515
import type { Annotations } from '../shared/types.js';
1616

17-
export default function AnnotationLayer() {
17+
export default function AnnotationLayer(): React.ReactElement {
1818
const documentContext = useDocumentContext();
1919
const pageContext = usePageContext();
2020

packages/react-pdf/src/Page/Canvas.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type CanvasProps = {
2424
canvasRef?: React.Ref<HTMLCanvasElement>;
2525
};
2626

27-
export default function Canvas(props: CanvasProps) {
27+
export default function Canvas(props: CanvasProps): React.ReactElement {
2828
const pageContext = usePageContext();
2929

3030
invariant(pageContext, 'Unable to find Page context.');

0 commit comments

Comments
 (0)