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

Convert to TypeScript and add public types #75

Open
jackjocross opened this issue Mar 14, 2019 · 11 comments
Open

Convert to TypeScript and add public types #75

jackjocross opened this issue Mar 14, 2019 · 11 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@jackjocross
Copy link
Collaborator

There have been a few issues related to TypeScript types (#13, #72), updating the source code to TypeScript would make future changes easier and give consumers better type support.

@jackjocross jackjocross added help wanted Extra attention is needed good first issue Good for newcomers labels Mar 14, 2019
@jackjocross jackjocross pinned this issue Mar 14, 2019
@jordandlaman
Copy link

jordandlaman commented Mar 14, 2019

So admittedly I am a TS amateur. I was just playing around with things and I did get it to config a bit easier if I added index.d.ts directly to the node_modules/cypress-image-snapshot/ with

import 'cypress';

declare global {
  namespace Cypress {
    interface Chainable {
      matchImageSnapshot: (options?: any) => void;
    }
  }
}

Obviously hacking a node_modules folder is a no no but I thought that might be a way to go though im not sure how much different it is from having a custom types folder somewhere else. I have seen a few other plugins use this sort of pattern and thought I would give it a shot.

@jackjocross
Copy link
Collaborator Author

Yep that makes sense! So if we add an index.d.ts to the root of cypress-image-snapshot and publish to NPM again, everyone will receive types without having to touch their node_modules directly.

I think what would be even better is if we rewrite to use TypeScript and then generate index.d.ts from our source, similar to how Formik does.

But creating types manually is definitely useful if we want to start there.

@makeupsomething
Copy link

Im pretty new to typescript but would like to have a go at this issue if it is ok?

@jackjocross
Copy link
Collaborator Author

@makeupsomething for sure give it a shot! I'm happy to review any PRs.

@lemcii
Copy link

lemcii commented Jul 9, 2019

import "cypress";
import "jest.d.ts";

import * as JestImageSnapshot from "jest-image-snapshot";

declare global {
    namespace Cypress {
        interface Chainable {
            matchImageSnapshot: (
                options?:
                    | string
                    | (Partial<
                          JestImageSnapshot.MatchImageSnapshotOptions &
                              Loggable &
                              Timeoutable &
                              ScreenshotOptions
                      >),
            ) => void;
        }
    }
}

Just based on what I understood from the readme, just a good stop gap for now.

@anujpunia
Copy link

So admittedly I am a TS amateur. I was just playing around with things and I did get it to config a bit easier if I added index.d.ts directly to the node_modules/cypress-image-snapshot/ with

import 'cypress';

declare global {
  namespace Cypress {
    interface Chainable {
      matchImageSnapshot: (options?: any) => void;
    }
  }
}

Obviously hacking a node_modules folder is a no no but I thought that might be a way to go though im not sure how much different it is from having a custom types folder somewhere else. I have seen a few other plugins use this sort of pattern and thought I would give it a shot.

Adding index.d.ts as you said still gives me error in the .ts spec file-
Property 'matchImageSnapshot' does not exist on type 'Chainable<undefined>'.

@Lukaszli
Copy link

Any solution? How to use this plugin with typescript?

@edupeeth
Copy link

I shifted to Percy. They have a free version as well and much smoother. Had no luck here.

@Keysox
Copy link

Keysox commented Dec 27, 2019

I went ahead and added typings for folks to use: DefinitelyTyped/DefinitelyTyped#41222

Now, all you need to do is yarn add @types/cypress-image-snapshot -D for this plugin to work with TypeScript!

@Svish
Copy link

Svish commented Jan 27, 2020

@Keysox Think the options are missing Cypress.ScreenshotOptions

@Keysox
Copy link

Keysox commented Jan 28, 2020

@Svish -- options have been added if you upgrade to 3.1.1 https://github.com/DefinitelyTyped/DefinitelyTyped/pull/41897/files#diff-603108fb86a139bc0934ce518b4267eeR10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

9 participants