-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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: wider compat TS types and CI checks to ensure correct type defs #6855
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This PR improves our TS types further to make sure they are usable in a TS environment where ES Modules are the target output. Our use of `export =` is problematic this environment as TypeScript does not allow `export =` to be used and it errors. The fix for the type issues to avoid `export =` is to instead define the functions that you gain access to when you import Puppeteer as top level functions in our `types.d.ts` file. We can do this by declaring them explicitly in `src/node.ts`. These are then rolled into `lib/types.d.ts` at build time. The downside to this is that we have to keep those declarations in sync with the Puppeteer API; should we add a new method to the `Puppeteer` class, we must add it to the `nodes.ts` declarations. However, this could easily be automated by a small script that walks the AST and generates these. I will do that in a follow-up PR, but I consider this low risk given how rarely the very top level API of Puppeteer changes. The nice thing about this approach is we no longer need our script that hacks on changes to `lib/types.d.ts`. To avoid yet more releases to fix issues in one particular TS environment, this PR also includes a suite of example setups that we test on each CI run. Each sample folder contains `good.ts`, which should have no TS errors, and `bad.ts`, which should have some errors. The test first packs Puppeteer into a tar, and then installs it from that tar into each project. This should replicate how the published package behaves when it is installed. We then check that we get no errors on `good.ts`, and the expected errors on `bad.ts`. We have a variety of test projects that cover both TS and JS source code, and CJS and ESM imports and outputs.
jackfranklin
force-pushed
the
yet-more-types
branch
from
February 10, 2021 08:34
6ed7736
to
d55bb76
Compare
mathiasbynens
requested changes
Feb 10, 2021
mathiasbynens
requested changes
Feb 10, 2021
mathiasbynens
approved these changes
Feb 10, 2021
This was referenced Mar 11, 2021
This was referenced Mar 15, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves our TS types further to make sure they are usable in a
TS environment where ES Modules are the target output. Our use of
export =
is problematic this environment as TypeScript does not allowexport =
to be used and it errors.The fix for the type issues to avoid
export =
is to instead define thefunctions that you gain access to when you import Puppeteer as top level
functions in our
types.d.ts
file. We can do this by declaring themexplicitly in
src/node.ts
. These are then rolled intolib/types.d.ts
at build time. The downside to this is that we have to keep those
declarations in sync with the Puppeteer API; should we add a new method
to the
Puppeteer
class, we must add it to thenodes.ts
declarations.However, this could easily be automated by a small script that walks the
AST and generates these. I will do that in a follow-up PR, but I
consider this low risk given how rarely the very top level API of
Puppeteer changes. The nice thing about this approach is we no longer
need our script that hacks on changes to
lib/types.d.ts
.To avoid yet more releases to fix issues in one particular TS
environment, this PR also includes a suite of example setups that we
test on each CI run. Each sample folder contains
good.ts
, which shouldhave no TS errors, and
bad.ts
, which should have some errors. The testfirst packs Puppeteer into a tar, and then installs it from that tar
into each project. This should replicate how the published package
behaves when it is installed. We then check that we get no errors on
good.ts
, and the expected errors onbad.ts
.We have a variety of test projects that cover both TS and JS source
code, and CJS and ESM imports and outputs.