Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Typescript: Cannot both import onlyOn and use cy.onlyOn #164

Open
samueldmeyer opened this issue Jun 22, 2021 · 5 comments
Open

Typescript: Cannot both import onlyOn and use cy.onlyOn #164

samueldmeyer opened this issue Jun 22, 2021 · 5 comments

Comments

@samueldmeyer
Copy link

In v2.6.0, Typescript threw errors when onlyOn was imported, but worked correctly for cy.onlyOn. Now in v2.6.1 (after #143), Typescript correctly types the onlyOn import, but cy.onlyOn does not have a type.

Is there any way to get both of these to work with Typescript?

import { onlyOn } from '@cypress/skip-test'; // error here in 2.6.0: File '.../node_modules/@cypress/skip-test/index.d.ts' is not a module.
onlyOn('integration', () => {
  describe('stuff', () => {
    cy.onlyOn('mac'); // Error here in 2.6.1: Property 'onlyOn' does not exist on type 'cy & EventEmitter'
  })
});
@estefafdez
Copy link

+1, I'm getting this error as well:

image

any idea? thanks!

@rdadoune
Copy link

rdadoune commented Aug 3, 2021

Looks like the types aren't being added to the global scope. The types in index.d.ts need to be updated from:

declare namespace Cypress {   
  // ... type definitions
}

To this:

declare global {
  declare namespace Cypress {
    // ... type definitions
  }
}

@estefafdez
Copy link

Any update on this? thanks!

@conversayShawn
Copy link

conversayShawn commented Oct 17, 2021

I was able to successfully import both by exporting the global scope in my support/index.d.ts.

Try the following:

export {};

declare global {
  namespace Cypress {
    // ... type definitions
  }
}

You can also find a minimal reproducible example here: https://github.com/conversaShawn/using-cypress-skip-test-plugin/tree/onlyOn

@muratkeremozcan
Copy link

muratkeremozcan commented Dec 29, 2022

Add to your cypress.d.ts file

export {}

declare global {
  namespace Cypress {
    interface Chainable<Subject> {
      /// plugins ///

      // the cypress skip-test plugin has an open issue with types, that is  we have declare these here
      // https://github.com/cypress-io/cypress-skip-test/issues/164
      /** https://www.npmjs.com/package/@cypress/skip-test
       * `cy.skipOn('sandbox')`
       */
      skipOn(
        nameOrFlag: string | boolean | (() => boolean),
        cb?: () => void,
      ): Chainable<Subject>
      /** https://www.npmjs.com/package/@cypress/skip-test
       * `cy.onlyOn('sandbox')`
       */
      onlyOn(
        nameOrFlag: string | boolean | (() => boolean),
        cb?: () => void,
      ): Chainable<Subject>

    }
  }
}

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

No branches or pull requests

5 participants