Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug] Typing support clash with user's custom typings #311

Open
david-fong opened this issue Jun 21, 2021 · 1 comment
Open

[Bug] Typing support clash with user's custom typings #311

david-fong opened this issue Jun 21, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@david-fong
Copy link

Current behavior:

The recommended way of adding typings support (import 'cypress-file-upload';) clashes with the user's typings for their custom commands.

// in support/commands.ts
/// <reference types="cypress" />
import 'cypress-file-upload'; // adding this causes the spec files to no longer detect the below custom command typings.

declare namespace Cypress { // In VS Code, "Cypress" gets greyed out as "unused".
  interface Chainable {
    ...
  }
}

I think this happens because the addition of the "import" keyword turns the file into a module. I tried adding the export keywords like so:

// in support/commands.ts
/// <reference types="cypress" />
import 'cypress-file-upload'; // adding this causes the spec files to no longer detect the below custom command typings.

export declare namespace Cypress { // In VS Code, "Cypress" gets greyed out as "unused".
  export interface Chainable {
    ...
  }
}

but that didn't work immediately. I think such a setup would require importing "Cypress" from the commands file in every spec file.

I am using Typescript 4.3

Suggested Fix:

This solution worked for me: use /// <reference types="cypress-file-upload" /> like so:

// in support/commands.ts
/// <reference types="cypress" />
/// <reference types="cypress-file-upload" />

declare namespace Cypress {
  interface Chainable {
    ...
  }
}

It doesn't require adding imports to all the spec files, which is nice.

@david-fong david-fong added the bug Something isn't working label Jun 21, 2021
@JoanSernaLeiton
Copy link

What happened with this bug? 🤔

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants