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

Add correct Types to Cypress examples #5800

Open
distante opened this issue Apr 12, 2024 · 0 comments
Open

Add correct Types to Cypress examples #5800

distante opened this issue Apr 12, 2024 · 0 comments

Comments

@distante
Copy link

Subject

Examples

Description

All the examples on the Cypress documentation have the types omitted here for simplicity. But they almost never work when using on a real Typescript project with strict types.

And trying to get the correct types is not really easy because they are usually types of a type of another type, and they break when it has overloads.

For example, the code given for Custom Queries gives this code:

Cypress.Commands.addQuery('focused2', function focused2(options = {}) {
  const log = options.log !== false && Cypress.log({ timeout: options.timeout })

  this.set('timeout', options.timeout)

  return () => {
    let $el = cy.getFocused()

    log &&
      cy.state('current') === this &&
      log.set({
        $el,
        consoleProps: () => {
          return {
            Yielded: $el?.length ? $el[0] : '--nothing--',
            Elements: $el != null ? $el.length : 0,
          }
        },
      })

    if (!$el) {
      $el = cy.$$(null)
      $el.selector = 'focused'
    }

    return $el
  }
})

But trying to use it will cause a typescript error on the timeout usage:

image

even when using the exact code that the original function

I think, it would be easier to get started if the types are defined from start.

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

No branches or pull requests

1 participant