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

[7.0.1] LaunchOptions and Page types are not exported from main #6816

Closed
AviVahl opened this issue Feb 4, 2021 · 12 comments
Closed

[7.0.1] LaunchOptions and Page types are not exported from main #6816

AviVahl opened this issue Feb 4, 2021 · 12 comments

Comments

@AviVahl
Copy link
Contributor

AviVahl commented Feb 4, 2021

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 7.0.1
  • Platform / OS version: Fedora 33
  • Node.js version: 14.15.4

What steps will reproduce the problem?

Please include code that reproduces the issue.

import puppeteer from 'puppeteer';
(async () => {
  const launchOptions: puppeteer.LaunchOptions = { devtools: true };
  const browser = await puppeteer.launch(puppeteerConfig);
...
})();

What is the expected result?

Interfaces are available on the namespace.
Work the same way it did with @types/puppeteer.

What happens instead?

They are not exposed. I'm sure there are many more. Will write any I notice here.

@AviVahl
Copy link
Contributor Author

AviVahl commented Feb 4, 2021

For:
page.on('dialog', (dialog) => dialog.dismiss());

dialog doesn't get inferred anymore.

@mathiasbynens
Copy link
Member

cc @jackfranklin

@wavded
Copy link

wavded commented Feb 4, 2021

also Browser isn't either

@thomassuckow
Copy link

and CDPSession. I don't think any of the types are actually being exported.

@thomassuckow
Copy link

thomassuckow commented Feb 4, 2021

So yes, no types are exported. Just the default is export. What should be happening is

export * from "common/Browser"
export * from "common/Connection"
export * from "common/DeviceDescriptors"
export * from "common/Page"
...

This ideally would happen in the node*.ts files and then the cjs shim at the root could export * instead of just the default as well.

Somehow the default export should also be a namespace...

@thomassuckow
Copy link

thomassuckow commented Feb 5, 2021

Also instead of re-exporting everything again, api-docs-entry already has all the things with types. So in cjs-entry*.d.ts you can also do:

export * from "./lib/cjs/puppeteer/api-docs-entry";

Still doesn't solve being able to do like import {devices} from "puppeteer-core";. That may be solvable by changing the export in src/node*.ts to export = initializePuppeteerNode[...]. Then the cjs-entry*.d.ts would be changed to export * from it as well. I haven't tested this though and I've never personally used the export = syntax.

@berstend
Copy link

berstend commented Feb 6, 2021

As a maintainer of a plugin framework for puppeteer this is quite a painful situation for me 😅

Does anyone know a trick to make TS ignore the built-in types and use @types/puppeteer instead? The latter being a little outdated, but at least they work 😄

edit, a hacky workaround: Install @types/puppeteer-core and use:

import type * as Puppeteer from 'puppeteer-core'

This will probably not work when consumers install puppeteer-core though.

@berstend
Copy link

berstend commented Feb 7, 2021

Nuclear option:

  • Create a src/types/puppeteer.ts file in your project
  • Add declare module 'puppeteer' { }
  • Copy paste the contents of this file between the curly brackets
  • String replace declare with export
  • Use import type * as Puppeteer from 'puppeteer'

🥲

@k-yle
Copy link

k-yle commented Feb 7, 2021

even in v7.0.1 the type definitions don't work at all if you use require() instead of import. I've opened #6827 to fix that by using the export = syntax.

cc @jackfranklin, I saw your comment on a7e3c2e

@thomassuckow
Copy link

Should be resolved by #6837 once it is merged/released

@AviVahl
Copy link
Contributor Author

AviVahl commented Feb 9, 2021

Fixed in v7.0.4. Thanks.

@AviVahl AviVahl closed this as completed Feb 9, 2021
@mceachen
Copy link

mceachen commented Feb 9, 2021

In case anyone else was using "@types/puppeteer and now using the built-in types, but wondering why your compile is still broken (even with v7.0.4): know that several type names have changed, like Request is now HTTPRequest, and Response is now HTTPResponse.

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

No branches or pull requests

7 participants