-
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
Can type definitions be more automatic for beginners? #1236
Comments
I think some documentation on the subject in our docs could also mitigate some of the issues for beginners. I created a new issue in our docs to get the ball rolling here: cypress-io/cypress-documentation#400. Our documentation is open source and contributions are welcome. 😄 |
I agree with you @NicholasBoll and was thinking along the same lines. I setup json schema |
Actually I found a perfect way to use our types @NicholasBoll Just add a comment to the JS spec file
Nothing else is necessary (neither typescript compiler, not Example: spec file without anything. No IntelliSense Spec file with reference comment: full IntelliSense in VSCode |
That's nice that the reference directive works in VSCode. I'm assuming that since it is part of the TypeScript language service it would also work in other IDEs using it (including WebStorm). Atom may not use the TypeScript language service for regular JS files without additional configuration. |
Yes, I agree - and for JS spec files using reference might be the fastest way to get IntelliSense |
So maybe having Cypress example code that uses the reference directive ( Creating a |
@jennifer-shehane can you look at this / reference this issue in your PR for a |
As brian mentioned, I've opened a WIP pull request for a doc specific to TypeScript support. I would love input + content suggestions as I am fairly new to using TypeScript myself! cypress-io/cypress-documentation#466 |
I think the triple-slash directive is a good quick solution to JS files. If the Cypress files are written in TypeScript, the developer should add a {
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"],
},
"include": [
"**/*.ts"
]
} The |
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 using js for my project, but have type checking turned on in VS code. Something that tripped me up was missing Not sure how common this is, but may help anyone who is having issues with type errors in their |
I'm also trying to get this set up; I've followed the guide as near as I could (but I did install cypress with yarn). I can start cypress and I can write tests, but I can't get typescript code competition to work, despite follow the docs and disabling any plugins I can imagine disrupt code completition. Here's what my workspace looks like: I've tried with EDIT: I had a look at the Developer Console in VSCode and it had lots of typescript errors... I then added this to {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
...
} and restarted VSCode in the folder with EDIT 2: that was probably because I selected "Typescript" in the bottom language selector drop-up. However, adding |
@haf restarting probably got it working. Those other settings are not required. I've had some caching issues lately with the Typescript server when getting other people set up. Maybe we should note restarting the Typescript server (Cmd+Shift+P and then type "restart TS server) or restart VS Code (or whatever editor is used). |
Yes I was thinking the same: add to the docs notes how to restart ts server in vs code
…Sent from my iPhone
On Sep 23, 2018, at 11:20, Nicholas Boll ***@***.***> wrote:
@haf restarting probably got it working. Those other settings are not required. checkJS will enable TS type checking on JS files.
I've had some caching issues lately with the Typescript server when getting other people set up. Maybe we should note restarting the Typescript server (Cmd+Shift+P and then type "restart TS server) or restart VS Code (or whatever editor is used).
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I've seen a lot of people ask how they can get type definitions for Cypress in JavaScript. As it is right now, this in not automatic. We spent a lot of time getting type definitions to "just work" for Cypress commands and various aspects of the Cypress API, but many people aren't getting that benefit. I've seen some people have success making a
tsconfig.json
file to force the TypeScript language service to work with Cypress type definitions. This definitely works better for VSCode. I've seen people give up trying to get it to work with WebStorm before just switching to VSCode.I use the
tsconfig.json
approach since my projects are written in TypeScript and that config file already exists. I don't have much experience with VSCode or other editors writing JavaScript and how types are pulled in. For most libraries that have exports, type definitions should be pulled in with a.d.ts
file next to the source sharing the same base name. Cypress defines globals so type definitions files need to be manually included. Maybe a solutions is for when Cypress lays down support files (config, folders, examples, etc), also lay down atsconfig.json
file? Anyone with experience with WebStorm or editors? Would that solution work?Is this a Feature or Bug?
Feature
The text was updated successfully, but these errors were encountered: