question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type 'Promise<any>' is not assignable to type 'CanReturnChainable' in Cypress

See original GitHub issue

Current behavior:

Having updated from Cypress 4.8, TypeScript will now not compile my support code. #435 was not insightful.

Desired behavior:

Compile my TypeScript. Either I’m doing something wrong or there is a bug.

Test code to reproduce

Cypress.Commands.overwrite(command, (originalFn, ...args) => {
  const origVal = originalFn(...args);
  return new Promise(resolve => {
    setTimeout(() => resolve(origVal), 1000);
  });
});

It fails similarly with Cypress.Promise as well. I’d like to avoid cy.wrap() unless necessary.

Versions

Cypress 4.9.0 macOS 10.15.5 Chrome 83

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
0x80commented, Aug 12, 2020

@jennifer-shehane I’m seeing similar behavior.

  • Yes, it’s code added to support/index.ts
  • It’s the compiler that complains. Weirdly enough the tests still run.
  • No preprocessor in plugins
  • Tsconfig file below
Cypress.Commands.add(
  "createReview",
  (payload: Partial<CreateReviewPayload>) => {
    const review = cleanObject<CreateReviewPayload>({
      title: payload.title || `[cy-test]`,
      description: "This is a review created for test purposes",
      tagIds: [],
      industryId: "__no_industry",
      type: "self-review",
      accountId: testAccountId,
      ...payload,
    });

    return functions
      .httpsCallable("createReview")(review)
      .then((result) => {
        const reviewId = result.data.reviewId as string;
        return firestore
          .collection("reviews")
          .doc(reviewId)
          .get()
          .then((snap) => ({
            id: reviewId,
            data: snap.data() as Review,
          }));
      });
  },
);

Error:

Argument of type '(payload: Partial<CreateReviewPayload>) => Promise<{ id: string; data: Review; }>' is not assignable to parameter of type '(...args: any[]) => CanReturnChainable'.
  Type 'Promise<{ id: string; data: Review; }>' is not assignable to type 'CanReturnChainable'.
    Type 'Promise<{ id: string; data: Review; }>' is missing the following properties from type 'Chainable<any>': and, as, blur, check, and 89 more.ts(2345)
{
  "compilerOptions": {
    "esModuleInterop": true,
    "jsx": "preserve",
    "lib": ["dom", "esnext"],
    "types": ["cypress", "node"],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "preserveConstEnums": true,
    "removeComments": false,
    "skipLibCheck": true,
    "checkJs": false,
    "sourceMap": true,
    "strict": true,
    "target": "es2018",
    "allowJs": false,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "baseUrl": ".",
    "paths": {
      "/*": ["./src/*"]
    }
  }
}

For me this issue also started when upgrading from 4.8 to 4.9

1reaction
cypress-bot[bot]commented, Sep 9, 2020

The code for this is done in cypress-io/cypress#8501, but has yet to be released. We’ll update this issue and reference the changelog when it’s released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type 'Promise<any>' is not assignable to type ... - Stack Overflow
I have just upgraded Cypress version to 4.9.0 from 4.8.0 and got: enter image description here. Example of test:
Read more >
Cypress.Promise
Cypress is promise aware so if you return a promise from inside of commands like .then() , Cypress will not continue until those...
Read more >
Type 'Promise<number | null>' is not assignable to ... - ADocLib
Cypress: Type 'Promise<any>' is not assignable to type 'CanReturnChainable' in Cypress Current behavior: Desired behavior: Test code to.
Read more >
Microsoft/TypeScript - Gitter
Type 'Promise<any>' is not assignable to type 'Promise<any>'. Property 'catch' is missing in type 'Promise<any>'.
Read more >
cli/types/cypress.d.ts - Fossies
1 /* eslint-disable @typescript-eslint/no-unused-vars */ 2 /// <reference path="./cypress-npm-api.d.ts" /> 3 /// <reference path=".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found