Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Viewer API definitions and include in CI #13930

Merged
merged 1 commit into from
Aug 27, 2021
Merged

Fix Viewer API definitions and include in CI #13930

merged 1 commit into from
Aug 27, 2021

Conversation

michael-yx-wu
Copy link
Contributor

The Viewer API definitions do not compile because of missing imports and
anonymous objects are typed as Object. These issues were not caught
during CI because the test project was not compiling anything from the
Viewer API.

As an example of the first problem:

/**
 * @implements MyInterface
 */
export class MyClass {
    ...
}

will generate a broken definition that doesn’t import MyInterface:

/**
 * @implements MyInterface
 */
export class MyClass implements MyInterface {
    ...
}

This can be fixed by adding a typedef jsdoc to specify the import:

/** @typedef {import("./otherFile").MyInterface} MyInterface */

See jsdoc/jsdoc#1537 and
microsoft/TypeScript#22160 for more details.

As an example of the second problem:

/**
 * Gets the size of the specified page, converted from PDF units to inches.
 * @param {Object} An Object containing the properties: {Array} `view`,
 *   {number} `userUnit`, and {number} `rotate`.
 */
function getPageSizeInches({ view, userUnit, rotate }) {
    ...
}

generates the broken definition:

function getPageSizeInches({ view, userUnit, rotate }: Object) {
    ...
}

The jsdoc should specify the type of each nested property:

/**
 * Gets the size of the specified page, converted from PDF units to inches.
 * @param {Object} options An object containing the properties: {Array} `view`,
 *   {number} `userUnit`, and {number} `rotate`.
 * @param {number[]} options.view
 * @param {number} options.userUnit
 * @param {number} options.rotate
 */

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the "add CI check task"-part of the commit message, is there something missing in the patch?
Also, it probably wouldn't hurt to actually mention (in the first line of the commit message) that it's the TypeScript definitions for the viewer that's being changed here.

web/annotation_layer_builder.js Show resolved Hide resolved
web/interfaces.js Outdated Show resolved Hide resolved
web/interfaces.js Outdated Show resolved Hide resolved
web/interfaces.js Outdated Show resolved Hide resolved
web/pdf_rendering_queue.js Outdated Show resolved Hide resolved
web/ui_utils.js Show resolved Hide resolved
web/ui_utils.js Outdated Show resolved Hide resolved
web/ui_utils.js Outdated Show resolved Hide resolved
web/interfaces.js Outdated Show resolved Hide resolved
@michael-yx-wu michael-yx-wu changed the title Fixes TS definitions and add CI check task Fixes Viewer TS definitions and use in CI Aug 23, 2021
web/pdf_page_view.js Outdated Show resolved Hide resolved
web/pdf_history.js Outdated Show resolved Hide resolved
web/pdf_rendering_queue.js Outdated Show resolved Hide resolved
web/text_layer_builder.js Show resolved Hide resolved
web/ui_utils.js Outdated Show resolved Hide resolved
external/dist/legacy/web/pdf_viewer.d.ts Show resolved Hide resolved
web/interfaces.js Outdated Show resolved Hide resolved
web/pdf_history.js Outdated Show resolved Hide resolved
web/pdf_rendering_queue.js Outdated Show resolved Hide resolved
Copy link
Contributor

@timvandermeij timvandermeij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with these comments addressed (and some of the remaining ones above). Thank you for improving the types and their testing!

web/xfa_layer_builder.js Outdated Show resolved Hide resolved
web/interfaces.js Outdated Show resolved Hide resolved
The Viewer API definitions do not compile because of missing imports and
anonymous objects are typed as `Object`. These issues were not caught
during CI because the test project was not compiling anything from the
Viewer API.

As an example of the first problem:

```
/**
 * @implements MyInterface
 */
export class MyClass {
    ...
}
```

will generate a broken definition that doesn’t import MyInterface:

```
/**
 * @implements MyInterface
 */
export class MyClass implements MyInterface {
    ...
}
```

This can be fixed by adding a typedef jsdoc to specify the import:

```
/** @typedef {import("./otherFile").MyInterface} MyInterface */
```

See jsdoc/jsdoc#1537 and
microsoft/TypeScript#22160 for more details.

As an example of the second problem:

```
/**
 * Gets the size of the specified page, converted from PDF units to inches.
 * @param {Object} An Object containing the properties: {Array} `view`,
 *   {number} `userUnit`, and {number} `rotate`.
 */
function getPageSizeInches({ view, userUnit, rotate }) {
    ...
}
```

generates the broken definition:

```
function getPageSizeInches({ view, userUnit, rotate }: Object) {
    ...
}
```

The jsdoc should specify the type of each nested property:

```
/**
 * Gets the size of the specified page, converted from PDF units to inches.
 * @param {Object} options An object containing the properties: {Array} `view`,
 *   {number} `userUnit`, and {number} `rotate`.
 * @param {number[]} options.view
 * @param {number} options.userUnit
 * @param {number} options.rotate
 */
```
@michael-yx-wu
Copy link
Contributor Author

@timvandermeij I noticed that this project doesn't squash when merging so I've rebased and squashed to a single commit to keep things clean.

@michael-yx-wu michael-yx-wu changed the title Fixes Viewer TS definitions and use in CI Fix Viewer API definitions and include in CI Aug 25, 2021
@michael-yx-wu
Copy link
Contributor Author

There are some things defined in display/api.js that I would like to export so that I can write something like:

import { PDFDocumentProxy, PDFPageProxy } from "pdfjs-dist";

As it is, I have to do a sub-module import, which is fragile if these items get refactored into different files:

import { PDFDocumentProxy, PDFPageProxy } from "pdfjs-dist/types/display/api";

Out of curiosity:

  1. Should these classes be exposed as part of the public api?
  2. If so, do you mind if I make that change here?

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Aug 26, 2021

I noticed that this project doesn't squash when merging so I've rebased and squashed to a single commit to keep things clean.

That's correct; we don't use separate fixup commits in this project.

import { PDFDocumentProxy, PDFPageProxy } from "pdfjs-dist/types/display/api";

Out of curiosity:
Should these classes be exposed as part of the public api?

No, those are not supposed to be directly exported through the API since a user is never intended to create/initialize them manually.
However, a similar question was asked in #12384 (comment) and a possible work-around was suggested in #12384 (comment).

If so, do you mind if I make that change here?

I'd suggest implementing the mentioned work-around in a separate PR, since it's not directly related to this one.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better, thank you!
(I'll let Tim take one last look as well, before we merge this.)

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/4717b69adbab00e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/4717b69adbab00e/output.txt

Total script time: 5.20 mins

Published

@timvandermeij timvandermeij merged commit c82381e into mozilla:master Aug 27, 2021
@timvandermeij
Copy link
Contributor

Thank you for contributing this!

@michael-yx-wu michael-yx-wu deleted the mw/fix-typings branch August 27, 2021 21:11
@michael-yx-wu
Copy link
Contributor Author

Thank you both for your patience as reviewers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants