Let's say you store the user login information used during tests in your Cypress config object.
1 | const { defineConfig } = require('cypress') |
A spec can grab the user login information and log in
1 | import { LoginPage } from '@support/pages/login.page' |
What is the type of the user value? We get it from the Cypress.env('users') object, which is ... "any". This propagates to the fields user.username and user.password

Note: I am using the any-xray VSCode plugin to highlight all any TS values at all times.

Let's fix the Cypress.env('users') type following this StackOverflow advice. We can add Cypress.env method definition to the ambient types file cypress/support/index.d.ts:
1 | /// <reference types="cypress" /> |
Tip: I am using inline type LoginInfo = import('../e2e').LoginInfo to avoid using import or /// <reference path=... which would change the cypress/support/index.d.ts to a "normal" TS module. I want to preserve cypress/support/index.d.ts as an ambient definition file, see this StackOverflow discussion
Let's take a look at the spec file again.

No more any values in our Cypress spec.
🎓 This blog post is based on a lesson in my Testing The Swag Store online course.