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:
Current behavior:
The recommended way of adding typings support (
import 'cypress-file-upload';
) clashes with the user's typings for their custom commands.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:
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:It doesn't require adding imports to all the spec files, which is nice.