-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Cannot pick up typings for Cypress with the Typescript recipe #1152
Comments
Does the tsconfig include Cypress? |
I have a {
"extends": "../tsconfig.json",
"include": [
"integration/*.ts",
"support/*.ts",
"../node_modules/cypress"
]
} |
Is this typescript compiler or typescript linter?
…Sent from my iPhone
On Jan 6, 2018, at 21:37, Attila Oláh ***@***.***> wrote:
I have a tsconfig.json file in projectRoot/cypress/tsconfig.json as the example shows:
{
"extends": "../tsconfig.json",
"include": [
"integration/*.ts",
"support/*.ts",
"../node_modules/cypress"
]
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Both, VS code doesn't see the typings neither the compiler. |
Hello, I have the same kind of issue with Cypress and typescript. I followed what is explained here : https://www.cypress.io/blog/2017/12/11/an-alternative-to-protractor-for-angular-projects/#Scaffolding-a-project in my own project. [...]/node_modules/cypress/types/index.d.ts What am I missing ? |
I wonder if TypeScript compiler does not find types for some reason. Like it does not see the included files referenced from non-root
|
same situation with vscode. |
@bahmutov aren't your files in nested directories? If that's the case, change this in |
Any resolution? Experiencing the same issue here (and it has nothing to do with nested paths, tried the solution above) |
We have this other issue that explains this... #1236 |
Try adding |
Finally got it to work with tsconfig.json like in https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/preprocessors__typescript-webpack: "include": [
"node_modules/cypress/types/index.d.ts",
"node_modules/cypress/types/blob-util.d.ts",
"node_modules/cypress/types/minimatch.d.ts",
"node_modules/cypress/types/bluebird.d.ts",
"cypress/**/*.ts"
] However, if i do something like "include": [
"node_modules/cypress/types/\*",
"cypress/**/*.ts"
]
|
@guetar A duplicate identifier like the is probably because you use Chai in your project. Cypress is currently using One of the solutions that worked well for me in this case (duplicate definitions) was to have a {
"extends": "../tsconfig",
"compilerOptions": {
"baseUrl": "../node_modules",
"target": "es5",
"types": ["cypress"],
},
"include": [
"**/*.ts"
]
} The A nuclear option would be to add |
Adding |
I'm just dropping into this thread, but - would it not be helpful to keep @types/cypress npm package published as this is the preferred way to handle types in TypeScript? It could help people who are struggling with hooking up the types from within Cypress' install - I know it should be unnecessary for most though. |
No, having to install separate |
Well, it seems that Vue.js does the same, includes types in core, but their configuration does not require defining |
because for us the main things that cause problems
|
Yeah, I was just getting to this conclusion in my reading. :/ Thanks. |
There are new docs explaining how to configure TypeScript support. We would love any feedback on whether our recommended setup solves the issues laid out in this issue. https://on.cypress.io/typescript-support There is also a new issue open proposing more "native" support of TypeScript (less config) if anyone has suggestions they'd like to add there: #1859 I am closing this issue, but please feel free to comment here again with any feedback/confusion! |
@jennifer-shehane - I'm running into an issue with code completion / Intellisense (VS Code) that feels akin to what is being described here. Per your recommendation, I'm adding a comment in the hopes that you'll see it - especially since I am following right along with the docs (as you suggested :) Environment
Install
RESULT
Setup - Cypress
RESULT (~/_CYPRESS)
RESULT (~/_CYPRESS/cypress)
Setup - tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../node_modules",
"types": [
"cypress"
]
},
"include": [
"**/*.*"
]
} Setup - .eslintrc.json
{
"plugins": [
"cypress",
"chai-friendly"
],
"env": {
"cypress/globals": true
},
"rules": {
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": 2
}
} VS Code
ISSUES
|
@Knaledge is there a reason you install Cypress globally? Do the types work when installing locally? |
@bahmutov As mentioned in Gitter, I sincerely appreciate the time you've spent having a look at this (especially with an artifact of a separate "story" / issue). For my particular circumstance, there's no "project" at the moment - I simply have Cypress installed on my Mac (via All that said, I could also just install Cypress "locally" (in a "project" folder - like When I started over, I went back a global install as it felt cleaner and made more sense. All that said - what do I put into |
Happens with local install too. Interesting how such a minor thing can go on for many many months without getting resolved. |
@ashnur We have not been able to replicate issues with Intellisense/tsconfig when Cypress is installed locally using VSCode. Could you provide the details and steps to replicate your issue please? |
For some miraculous reason it has resolved itself and as I am not really in the mood if debugging something as big as Cypress, so I was very careful not to even shut down my machine, in case it stops working again. |
It shouldn't be necessary if you've set up everything the way the TypeScript Doc laid out. |
@ashnur I've noticed sometimes the Typescript server needs to be restarted (cache invalidation issue). You can do this by either from the command palette |
This worked for me! Thank you! |
Just a quick note for Atom: the second |
This was my issue- prettier is formatting that to |
Here is what I use and I do not have to add I have my custom typings under /// <reference types="cypress" />
declare namespace Cypress {
interface Chainable<Subject> {
getByDataTest(tag: string): Chainable<any>
}
} And my {
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"],
"typeRoots": ["./support"]
},
"include": ["**/*.ts"]
} And TypeScript is finally happy describe('when I want to select by data test tag', () => {
it('should select by data test tag', () => {
cy.getByDataTest('yolo').should('exist')
});
}); |
@GentryRiggen added the reference works. sadly a bit of additional coding. |
I finally figured out that, for some reason, awesome-typescript-loader is incompatible with the cypress-webpack-preprocessor-plugin, and throws these errors. Switching to ts-loader fixed things for me. |
I had the same error. Adding the following to my tsconfig.json solved the problem for me.
|
Simply adding |
After trying all the solutions above, I just had to mix the two most useful comments for me by @NicholasBoll : #1152 (comment) ...and it works as it should. : ) 👍 |
What is in the support/index file? |
The
Then just restart your Typescript server in VS Code. |
It's really helping :); Thank you very much!) |
One has to follow the below step after making the necessary config changes: You may have to restart your IDE's TypeScript server if the setup above does not appear to work. For example: VS Code (within a .ts or .js file):
If that does not work, try restarting the IDE. |
Is anyone able to import |
Just fyi, if youre using yarn, in a nested project, you may need to download the node_modules in that nest project (I used npm install) for typescript to find the types |
but how is this possible because there is no |
After running various updates today (macOS and brew formulae and casks), I started seeing a few errors in the `integration_tests` folder: - in `integration_tests/tsconfig.json`, TS2688: `Cannot find type definition file for 'cypress'` and `Cannot find type definition file for 'express-session'` - in `integration_tests/**/*.ts`, TS2304: `Cannot find name 'cy'` and `Cannot find name` with various other Cypress-related objects The `typeRoots` change fixes the former, while the `include` change fixes the latter. This was hard to debug, but the following helped: - https://stackoverflow.com/a/53938729/4002016 (I think - as well as the Approved Premises config) - cypress-io/cypress#1152 (comment)
Current behavior:
Cypress ships with bundled typings but the compiler cannot pick up the typings for Cypress and fails on encountering a
cy
call.Desired behavior:
Typescript compiler can pick up the typings and test files compile successfully.
How to reproduce:
cy
Test code:
See above
Additional Info (images, stack traces, etc)
The text was updated successfully, but these errors were encountered: