Cypress: Latest Cypress + TypeScript results in error due to out of date jquery type definitions imported by cypress

Created on 17 Aug 2018  路  10Comments  路  Source: cypress-io/cypress

Current behavior:

TypeScript Error

node_modules/@types/jquery/index.d.ts:6107:66 - error TS2344: Type '"timeout" | "onreadystatechange"
 | "responseType" | "withCredentials" | "msCaching"' does not satisfy the constraint '"abort" | "ope
n" | "timeout" | "onreadystatechange" | "responseType" | "withCredentials" | "readyState" | "respons
e" | "responseText" | "responseURL" | "responseXML" | "status" | ... 21 more ... | "dispatchEvent"'.

  Type '"msCaching"' is not assignable to type '"abort" | "open" | "timeout" | "onreadystatechange"
| "responseType" | "withCredentials" | "readyState" | "response" | "responseText" | "responseURL" |
"responseXML" | "status" | ... 21 more ... | "dispatchEvent"'.

   interface XHRFields extends Partial<Pick<XMLHttpRequest, 'onreadystatechange' | 'respon
seType' | 'timeout' | 'withCredentials' | 'msCaching'>> { }

Desired behavior:

No Error.

Steps to reproduce:

npm init -y
npm install typescript cypress
npx tsc --init --lib es6,dom
npx tsc

image

Versions

+ [email protected]
+ [email protected]

Suggested fix

Bumping the jquery type definitions here : https://github.com/cypress-io/cypress/blob/68b9c91839e0ead57fcf17f8c161533bf7fd4497/cli/package.json#L42 should (because DefinitelyTyped is updated to TS 3.0) fix the issue :rose:

typescript

Most helpful comment

Verified fixed :rose:

Steps for verification

Get error:

npm init -y
npm install typescript cypress
npx tsc --init --lib es6,dom
npx tsc

Fix Error:

rm -rf ./node_modules/@types/jquery
npm i @types/[email protected]
npx tsc

All 10 comments

Opened a PR to bump @types/jquery - could you try your example above within that fix? https://github.com/cypress-io/cypress/pull/2369

Verified fixed :rose:

Steps for verification

Get error:

npm init -y
npm install typescript cypress
npx tsc --init --lib es6,dom
npx tsc

Fix Error:

rm -rf ./node_modules/@types/jquery
npm i @types/[email protected]
npx tsc

Is there a workaround until this gets merged? I can't compile my tests

@sarink stay on ts 2.9 馃尮

Can the fix for this (https://github.com/cypress-io/cypress/pull/2369) get released in a patch version? Perhaps 3.1.1?

@jennifer-shehane Would you be able to do a patch release? It's currently impossible to use Cypress for anyone that's on TypeScript 3.

We will soon, promise @sindresorhus

This is a problem for anyone using Angular 7 because it requires Typescript 3. 馃槩

Actually, I managed to fix my build by just explicitly adding types for jquery: yarn add @types/jquery.

Somehow it still does not work. @martindzejky solutions work as a temporary workaround. 馃檪

Was this page helpful?
0 / 5 - 0 ratings