Set Aliased Value TypeScript Type Value In Cypress Tests @gleb
Set Aliased Value TypeScript Type Value In Cypress Tests  @gleb
Uploaded November 2023 | Updated November 2026, 2 days ago
Whenever you get an aliased value using cy.get(alias name) command, it assumes by default that the value is a jQuery object. But if you store an alias to a string, for example, TypeScript will complain:
cy.wrap("hello").as("greeting")
cy.get("@greeting")
// TypeScript thinks you are checking a jQuery object :(
.should("equal", "hello")
This video shows a fix from my course "Testing The Swag Store" https://cypress.tips/courses/swag-store where I declare the type for the yielded value when calling "cy.get". Since YouTube does not allow angular brackets, I will use LT and RT strings
cy.get LT string RT ("@greeting")
// TS knows the current value is a string
.should("equal", "hello")
For more tips, read my blog post "Cypress v10 Tips and Tricks" glebbahmutov.com/blog/cypress-v10-tips
Set Aliased Value TypeScript Type Value In Cypress TestsFilter And Parse Table Cells To Confirm The Sum Of PricesTable Pagination Solution Using Plain DOM MethodsAdd A Cypress Test To Confirm The Filtered List Of ProjectsPartial Value MatchRefactor Cypress Api Tests Part 2: Set Up The IntelliSenseRemove Class From Sampled ElementsRefactor Cypress API Tests Part 1: Use cy-spok PluginCheck If Cypress Has An Alias Before Getting ItVerify Cypress Component Prop Calls Using Stubs, cypress-map, and cy-spok
gleb bahmutov |

Set Aliased Value TypeScript Type Value In Cypress Tests

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER