-
Notifications
You must be signed in to change notification settings - Fork 3.3k
PROPOSAL: type-safe cy.task function #32014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
@jennifer-shehane this PR draft adds type-safety to cy.task calls Autocomplete works and will have a type error in VSCode when the types mismatch (input/output) or when the cy.task method is the wrong name I don't know of a better way of reading from the Cypress Config File since this only has to do with the code editor types side Please let me know what the team thinks about this feature |
Does Cypress' validation of cy.task function calls happen at runtime? Or is it type-checked internally? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Cypress Type Definitions Fail with Custom Config Paths
The hardcoded import path ../../../cypress.config
in cli/types/cypress.d.ts
is brittle. It assumes a specific, non-universal project structure where the user's cypress.config
file is exactly three directories up from the types file (located within the Cypress package in node_modules
). It also assumes the config file exports a CypressTasks
property. This will cause TypeScript compilation errors for most Cypress installations, breaking the new type-safe cy.task
functionality.
cli/types/cypress.d.ts#L5-L6
cypress/cli/types/cypress.d.ts
Lines 5 to 6 in 40c99ed
type AllTasks = typeof import('../../../cypress.config')['CypressTasks'] |
Was this report helpful? Give feedback by reacting with 👍 or 👎
THIS IS A PROPOSAL
adds type-safety and autocomplete to cy.task function
cypress.config.js
tasks.js
cypress/e2e/spec.cy.js
jsconfig.json