ea2b0d1f62
This commit updates the JSHandle class to take a generic representing the underlying object that it's wrapping. We can then define `ElementHandle` as a class that extends `JSHandle<Element>` and begin to get better type inference. Prior to this commit the following code would have `d` set to `any`: ``` const div: page.$<HTMLDivElement>('div') const text = await div.evaluate(d => d.innerText) ``` You could work around this in two ways: ``` const text = await div.evaluate<(d: HTMLDivElement) => string>(d => d.innerText) const text = await div.evaluate((d: HTMLDivElement) => d.innerText) ``` But both of these have two issues: 1. Requires the user to type extra information. 2. There's no type checking: in the code above I could type `d` as `number` and TS would be happy. With the change here to `evaluate` the user can now type the original code: ``` const div: page.$<HTMLDivElement>('div') const text = await div.evaluate(d => d.innerText) ``` And TypeScript will know that `d` is an `HTMLDivElement`. This change brings us inline with the approach that @types/puppeteer takes. If we land this and it works, we can do the same with `evaluateHandle` to hopefully make a similar improvement there. BREAKING: because this changes the types, which were previously `any`, this is technically a breaking change as users using TS could start getting errors after this change is released. |
||
---|---|---|
.. | ||
check_public_api | ||
preprocessor | ||
.gitignore | ||
cli.js | ||
Message.js | ||
README.md | ||
Source.js |
DocLint
Doclint is a small program that lints Puppeteer's documentation against Puppeteer's source code.
Doclint works in a few steps:
- Read sources in
lib/
folder, parse AST trees and extract public API. Note that we run DocLint on the outputted JavaScript inlib/
rather than the source code insrc/
. We will do this until we have migratedsrc/
to be exclusively TypeScript and then we can update DocLint to support TypeScript. - Read sources in
docs/
folder, render markdown to HTML, use puppeteer to traverse the HTML and extract described API. - Compare one API to another.
Doclint is also responsible for general markdown checks, most notably for the table of contents relevancy.
Running
npm run doc
Tests
Doclint has its own set of jasmine tests, located at utils/doclint/test
folder.
To execute tests, run:
npm run test-doclint