Typings not working properly
refucktor opened this issue · comments
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.1npm
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
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
@refucktor and @tonoslav, please, try to apply this PR #15
Probably it will resolve your problem.
@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
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.