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

Typings not working properly #16

Closed
refucktor opened this issue Jan 23, 2020 · 5 comments
Closed

Typings not working properly #16

refucktor opened this issue Jan 23, 2020 · 5 comments

Comments

@refucktor
Copy link

Bug

  • package version:
"@types/jest": "^24.9.0",
"jest": "^24.9.0",
"jest-chain": "^1.1.2",
"jest-extended": "^0.11.2",
  • node version: 12.14.1
  • npm version: 6.13.6

Relevant code or config

//example.spec.ts
expect(response).not.toMatchObject({test: 'testing_purpose'})
//global.d.ts
import 'jest-extended';
import 'jest-chain';
//app.d.ts
declare global {
    namespace jest {
        interface Matchers<R> {
            toDeepKeysEqual(expected: AnyObject);
        }
    }
}

Scenario:

  • After upgrading to the latest @types/jest version (see version on top) some matchers start giving the following error
    Property 'not' does not exist on type 'ChainedMatchers<any>'.

  • Custom expect extensions are not working as well:
    TS2339: Property 'toDeepKeysEqual' does not exist on type 'ChainedMatchers<any>'.

  • I'm using Webstorm and typescript setup properly... everything was working perfectly until I update the package previously mentioned.

  • If I remove the import of jest-chain everything goes back to work

Any idea what might cause the problem or how to solve it.
Thanks in advance

@tonoslav
Copy link

I changed this file https://github.com/mattphillips/jest-chain/blob/master/types/index.d.ts
I am not 100% sure it is correct change but everything works now.

You can update index.d.ts file in node_modules\jest-chain\types\index.d.ts

declare namespace jest {
  type ChainedMatchers<R> = { [K in keyof AndNot<jest.Matchers<R>>]: AndNot<jest.Matchers<ChainedMatchers<R>>>[K] };

  interface Expect {
    /**
     * The `expect` function is used every time you want to test a value.
     * You will rarely call `expect` by itself.
     *
     * @param actual The value to apply matchers against.
     */
    <T = any>(actual: T): ChainedMatchers<T>;
  }
}

Added AndNot<> wrapper here

image

@Userbit
Copy link

Userbit commented Jan 27, 2020

@refucktor and @tonoslav, please, try to apply this PR #15
Probably it will resolve your problem.

@refucktor
Copy link
Author

@refucktor and @tonoslav, please, try to apply this PR #15
Probably it will resolve your problem.

Thanks @Userbit , I will try it soon and give you feedback

@mattphillips
Copy link
Owner

This should be fixed by: DefinitelyTyped/DefinitelyTyped#41766

Please try using the latest @types/jest.

Going to close this for now, but feel free to re-open and let me know if this is still an issue.

@tonoslav
Copy link

For me I still getting error
@types/jest@24.9.1 or @types/jest@24.5.1
"jest": "^25.1.0",
"jest-chain": "^1.1.4",
"jest-expect-message": "^1.0.2",
"jest-extended": "^0.11.5",
"typescript": "^3.7.5"

image

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

No branches or pull requests

4 participants