Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Compiler errors extending PuppeteerEnvironmentΒ #546

@colinrotherham

Description

@colinrotherham

πŸ› Bug Report

The class interface for PuppeteerEnvironment is a named default export:

export { JestPuppeteerConfig, JestPuppeteerGlobal, PuppeteerEnvironment as default };

To Reproduce

But when importing into Node.js (without Babel or a bundler) the source now differs to the types:

class CustomEnvironment extends PuppeteerEnvironment {} // Actual default export, won't compile
class CustomEnvironment extends PuppeteerEnvironment.default {} // But types use named export

Libraries like glob support both by adding default as a property
isaacs/node-glob@c381907

Expected behavior

Compilation should complete without error but the following is shown:

src/custom-environment.js:3:33 - error TS2507: Type 'typeof import("/path/to/project/node_modules/jest-environment-puppeteer/dist/index")' is not a constructor function type.

3 class CustomEnvironment extends PuppeteerEnvironment {
                                  ~~~~~~~~~~~~~~~~~~~~

src/custom-environment.js:8:22 - error TS2339: Property 'global' does not exist on type 'CustomEnvironment'.

8     console.log(this.global)
                       ~~~~~~

src/custom-environment.js:9:22 - error TS2339: Property 'context' does not exist on type 'CustomEnvironment'.

9     console.log(this.context)
                       ~~~~~~~

Link to repl or repo (highly encouraged)

Reproduced in example repo:
https://github.com/colinrotherham/jest-environment-puppeteeer-types

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions