Open Lakitna opened 2 years ago
I tried to extend the return type of defineConfig
(ConfigOptions) and was unable to do so. We define it as type ConfigOptions
, but if it was declared as an interface
you should be able to export .d.ts
file that would merge the interfaces like so:
// my-package/types/index.d.ts
declare global {
namespace Cypress {
interface ConfigOptions {
requestBaseUrl?: string;
}
}
}
As a workaround, you could export your own defineConfig
function that adds your desired values:
interface MyConfigOptions extends Cypress.ConfigOptions {
requestBaseUrl: string;
}
const myDefineConfig = (config: MyConfigOptions): MyConfigOptions =>
config;
// usage
export default myDefineConfig({ ... });
That's a better workaround than the ones I had up to now, but is still limited in that only 1 plugin can change the config types. In any case, progress :)
Sounds like it would be a relatively easy fix on the Cypress side to make Cypress.ConfigOptions
into an interface, right? Is anyone willing to share an approximate ETA?
Hey @Lakitna, we don't currently have this prioritized but we would absolutely accept a PR that updates the types to work like you've described.
What would you like?
The ability for extension authors to extend the types used in the
defineConfig
function when configuring Cypress viacypress.config.ts
(or, to a lesser extent,cypress.config.js
).Why is this needed?
I am the author of
cypress-commands
which adds a few new commands and extends some others.One of the extended commands also adds a new property to the config file. In this case, the extended
cy.request()
uses therequestBaseUrl
config property. Details on the command: https://github.com/Lakitna/cypress-commands/blob/develop/docs/request.mdI have tried to extend it using the same approach as with adding commands to the types. It does not work as-is, the type validation keeps throwing errors.
Other
To make things seamless for users, I want to refrain from using/recommending workarounds like:
defineConfig
. This skips the type checks.cypress.config.js
instead of.ts
. This skips the type checks.