Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add types to Cypress.env?

I have this cypress.json config file:

{
  "env": {
    "example": "Hello World!"
  }
}

In my tests:

Cypress.env("example")

Can I add any kind of type defintion to the env system? (to work with Typescript or eslint) I would love to use intellisense here.

like image 231
Lars Flieger Avatar asked Oct 16 '25 02:10

Lars Flieger


1 Answers

From cypress.d.ts

interface Cypress {
  /**
   * Returns specific environment variable or undefined
   * @see https://on.cypress.io/env
   * @example
   *    // cypress.json
   *    { "env": { "foo": "bar" } }
   *    Cypress.env("foo") // => bar
  */
  env(key: string): any
}

so you can extend it with

declare namespace Cypress {
  interface Cypress {
    env(key: "example"): string
  }
}

which gives intellisense (method) Cypress.Cypress.env(key: "example"): string (+6 overloads)

like image 176
Fody Avatar answered Oct 18 '25 17:10

Fody



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!