Skip to content

Instantly share code, notes, and snippets.

@alfredlucero
Last active June 10, 2021 15:01
Cypress Tips/Tricks - Typing Environment Variables
// Can import types from other files using TypeScript's typed imports functionality
type TestEnvironment = import('../utils/testEnv').TestEnvironment;
// Or you can define the types here as well in this type definition file
type ApiHost = "https://staging.api.com" | "https://testing.api.com" | string;
declare namespace Cypress {
interface Cypress {
// This types out our Cypress.env("key") calls better
env(key: 'apiHost'): ApiHost | undefined;
env(key: 'testEnv'): TestEnvironment | undefined;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment