Skip to content
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

[Feature] Update the readme with instructions on how to add the attachFile command to typescript intellisense #202

Closed
UncleGus opened this issue May 26, 2020 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@UncleGus
Copy link

UncleGus commented May 26, 2020

Current behavior:

When using the .attachFile() command, intellisense doesn't recognise it and underlines it red.

Desired behavior:

Intellisense should recognise the command. This can be achieved by adding the command to index.d.ts in the cypress/support folder. More details in the Cypess custom commands documentation.

Versions

N/A

@UncleGus UncleGus added the enhancement New feature or request label May 26, 2020
@MCFreddie777
Copy link

Would help a lot.

@abramenal
Copy link
Owner

Hi @UncleGus @MCFreddie777 did you have a chance to check #167

index.d.ts is currently defined, but for some reason multiple users experience this issue. I'm not sure how exactly it should be fixed

@peterkrieg
Copy link

@abramenal I just posted (#167 (comment)) in that issue (which I think can be closed if the solution works for people).

I'd be happy to make a small PR outlining how to add the types to the tsconfig.json. I'm thinking it could be a small blurb similar to how cypress-testing-library does it here: https://github.com/testing-library/cypress-testing-library#with-typescript

Let me know what you think!

@abramenal
Copy link
Owner

Hi @peterkrieg
Thanks for this solution! While waiting for someone else's feedback we can work on the PR.
Example that you mentioned is perfect – we can copy both With TypeScript and Intellisense for JavaScript with VS Code sections and put it between Installation and Usage too 👍

@MCFreddie777
Copy link

Update:
I tried multiple solutions but only one worked.

Previously I used typeRoots in my project, so I tried to add it there:

// /cypress/tsconfig.json
  "typeRoots": [
            "../node_modules/@types",
            "../node_modules/cypress/types",
            "../types",
            "../node_modules/cypress-file-upload"
        ]

Using this solution, my IDE (WebStorm) stopped complaining about not existing property, but when I ran the tests, I started getting errors such as Cannot find type definition file for 'dist' or 'node_modules'.

Maybe its worth to mention that I'm running cypress@4.12.1 but without out-of-the-box typescript, still using @cypress/webpack-preprocessor to transpile typescript into js.

Well, I started trying more solutions as adding "../node_modules/cypress-file-upload/types" into the typeRoots, not working.
Tried adding /// <reference types="Cypress" /> to the beginning of file where I am using the attachFile function with no luck.

The only solution that worked is:

// /cypress/tsconfig.json
  "types": ["cypress", "cypress-file-upload"],
   "typeRoots": [
         "../node_modules/@types",
         "../types"
   ]

You can use both typeRoots and types in your cypress/tsconfig.json file.

@andrico1234
Copy link
Contributor

The only solution that worked is:

// /cypress/tsconfig.json
"types": ["cypress", "cypress-file-upload"],
"typeRoots": [
"../node_modules/@types",
"../types"
]
You can use both typeRoots and types in your cypress/tsconfig.json file.

This worked for me straight away, I'm surprised that this is not documented in the README.

@abramenal
Copy link
Owner

abramenal commented Dec 22, 2020

I think README indeed lacks of clarity on using command with TS, might be a good improvement for upcoming v5 release.
In the meantime, if someone has courage to do it now, would really appreciate it!

@andrico1234
Copy link
Contributor

I whipped up a super quick MR to include @MCFreddie777 's .tsconfig changes to the README, you can find it here: #246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants