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

Cypress types need refactoring #14991

bahmutov opened this issue Feb 9, 2021 · 2 comments · Fixed by #14992

Cypress types need refactoring #14991

bahmutov opened this issue Feb 9, 2021 · 2 comments · Fixed by #14992


Copy link

bahmutov commented Feb 9, 2021

Cypress v6.4.0

I have described how to get rid of the global Cypress objects like cy, Cypress, assertion methods, and Mocha's functions in the blog post While looking at the types I have noticed a few weird things:

  • the cypress-global-vars.d.ts imports the EventEmitter types, thus including the type NodeEventEmitter, but that type is already used in cypress.d.ts without an explicit import

Thus, to work around these things I had to repeat a bunch of code from Cypress types, see

Also just noticed that our on Action type does not return the object, thus this code is invalid but runs just fine

// @ts-check
/// <reference types="cypress" />
Cypress.on('test:before:run', () => {
  console.log('before running a test')
}).on('test:after:run', () => {
  console.log('after running a test')

Screen Shot 2021-02-09 at 9 53 38 AM

So we should fix the Action interface to return this I think


Rejigger the type imports a little bit. The end-user will not notice a difference, but the types will actually make more sense and will be easier to work with if one wants to avoid global type clashes.

Outside of the scope

Screen Shot 2021-02-09 at 9 22 17 AM

We can merge the type in our code and have the cy be just of type cy, same for the top-level Cypress type

I have opened #15022 for this part

Copy link

cypress-bot bot commented Feb 10, 2021

The code for this is done in cypress-io/cypress#14992, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Copy link

cypress-bot bot commented Feb 16, 2021

Released in 6.5.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v6.5.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Feb 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

Successfully merging a pull request may close this issue.

1 participant