Closed gijsroge closed 5 years ago
You need to either exclude tests/e2e
in the root tsconfig.json
or add "types": ["cypress"]
to it, because it's the default tsconfig that's used when running yarn serve
.
Also please note we don't ship TS support for cypress by default. Your setup is not complete. You'll need a webpack preprocessor config and should enable it in plugin.js
. See https://github.com/cypress-io/cypress-and-jest-typescript-example/blob/master/cypress/plugins/cy-ts-preprocessor.js and https://github.com/cypress-io/cypress-and-jest-typescript-example/blob/master/cypress/plugins/index.js
@sodatea Those links are broken now; where can I find them?
If you are using Cypress 3, the permanent link for the example is here: https://github.com/cypress-io/cypress-and-jest-typescript-example/tree/cdc24ff6595190790b6bc2c973a084efe1c11de7/cypress/plugins
If you are using Cypress 4.4+, TypeScript test files are supported without using special preprocessors plugins, so just ignore the linked example and read Cypress's official documentation https://docs.cypress.io/guides/tooling/typescript-support.html
hello, I modified the tsconfig.json file from my project's root folder to ignore the cypress folder. Try this too to test, here it worked.
{ //... tsconfig.json file "exclude": ["src/main/test/cypress"] }
Hello, as others said, it is tsconfig.json issue. My file is like the below:
{ "compilerOptions": { "target": "es5", "lib": ["es5", "dom"], "types": ["cypress"] }, "include": ["**/*.ts"] }
refer this articlehttps://dzone.com/articles/cypress-typescript-end-to-end-automation-testing-from-scratch
I had the same issue and once i add types in "tsconfig.json", scripts are executing without errors
I have resolved this with this final config
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom", "dom.iterable", "esnext"],
"types": ["node"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": "src"
},
"include": ["src", "**/*.ts"]
}
react just sharing as it might helpful for others
Our Cypress files raise hundreds of problems because keywords like "cy", "it" or "expect" are not recognised by TypeScript, e.g. Cannot find name "cy" ts(2304).
After some investiation we noticed that this is caused by a breaking change in Typescript 5.1 with typeRoots
(https://www.typescriptlang.org/tsconfig#typeRoots) - we were using Typescript 5.0.4 in our package.json before. VSCode is always using the latest Typescript version (could be set to "Use workspace version" -> https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-newer-typescript-versions) & therefore the breaking change caused these hundreds of problems.
Solution:
As soon as we removed the typeRoots
entry from our frontend/tsconfig.json
, the problems disappeared.
We now keep the TypeScript version of VSCode & our package.json in sync, to prevent similar problems in the future, with the following VSCode setting: https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript
if adding the types doesn't solve the erros, just restart the TS server, if you are in vscode open command pallete and choose Typescript: Restart TS Server
and the should solve it
Perhaps the worst solution ever: rename file extension from *.cy.ts
to *.cy.js
No TypeScript no Typing problems :)
Perhaps the worst solution ever: rename file extension from
*.cy.ts
to*.cy.js
No TypeScript no Typing problems :)
Maybe we should delete the codebase as well
No code, no problems
haha jk
Rather than deleting your code base, you can just open your tsconfig.json
in the root folder and add the include
option to have a value of ["src", "**/*.ts"]
{
....
"include": ["src", "**/*.ts"]
}
Also make sure that in your cypress
folder you have a tsconfig.json
that looks similar to this:
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
},
"include": ["**/*.ts"]
}
Adding types reference to cypress resolved this issue for me.
Solution 1: Add the following to the top of spec files
/// <reference types="cypress" />
...
Solution 2: Add the following to the tsconfig.json
{
"compilerOptions": {
"types": [
"cypress",
]
}
}
Version
3.9.1
Reproduction link
https://github.com/gijsroge/typescript-vue-cli-cypress-typings
Environment info
Steps to reproduce
What is expected?
Should compile without errors.
What is actually happening?
Compiles with errors.
This might just be a Cypress related issue, I'm honestly not sure.
I followed the Typescript guide on Cypress.io -> https://docs.cypress.io/guides/tooling/typescript-support.html#Transpiling-TypeScript-test-files This might also be useful: https://github.com/cypress-io/cypress/issues/1152