Definitelytyped: @types/jest V24.0.20 produces error: TS2428: All declarations of 'Matchers' must have identical type parameters

Created on 29 Oct 2019  Â·  6Comments  Â·  Source: DefinitelyTyped/DefinitelyTyped

If you know how to fix the issue, make a pull request instead.

  • [X] I tried using the @types/jest package and had problems.
  • [X] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [X] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [X] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @NoHomey @jwbay @asvetliakov @alexjoverm @epicallan @ikatyang @wsmd @JamieMason @douglasduteil @ahnpnl @JoshuaKGoldberg @UselessPickles @r3nya @Hotell @sebald @andys8 @antoinebrault @Favna @gstamac @ExE-Boss @quassnoi @Belco90 @tonyhallett

After updating @types/jest to 24.0.20, we had the following error. We were able to fix the issue by downgrading to 24.0.19, so this appears to be an issue with the changes in 24.0.20.

`ï½¢atlï½£: Using [email protected] from typescript
ï½¢atlï½£: Using tsconfig.json from C:/Projects/projectname/tsconfig.json
ï½¢atlï½£: Checking started in a separate process...
ï½¢atlï½£: Checking finished with 2 errors
Child

ERROR in [at-loader] ./node_modules/jest-enzyme/lib/index.d.ts:7:15
TS2428: All declarations of 'Matchers' must have identical type parameters.

ERROR in [at-loader] ./node_modules/@types/jest/index.d.ts:639:15
TS2428: All declarations of 'Matchers' must have identical type parameters.
pm ERR! code ELIFECYCLE `

Most helpful comment

T = {}
See comment

R should be either void or Promise<void> but definitely typed files go through dtslint which was erroneously preventing this.

All 6 comments

Yeah, that’s because of #39243.

I read through #39243, but I didn't discern from that issue what steps I should be taking. Do I need to wait until for a change to @types/jest? Wait for jest-enzyme to catch up to the change in @types/jest? Or is there another package I can update to resolve my error? For now, I have pinned the version at 24.0.19.

You need to wait for jest-enzyme to add the new T type parameter to Matchers.

I see this in the types file
// should be R extends void|Promise<void> but getting dtslint error interface Matchers<R, T = {}> {

jest-extended has this interface Matchers<R, T = void> {
https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts#L5

Which is right? should it be T = {} or T = void ?

T = {}
See comment

R should be either void or Promise<void> but definitely typed files go through dtslint which was erroneously preventing this.

@kbradl16
On further thoughts I think T should just be T. The default was there for backwards compatibility, given that it is present T should be T.

I also think that there is an error with toContainEntry. Also probably with toContainEntries, toContainAllEntries and toContainAnyEntries.

toContainEntry<T>(entry: [keyof T, T[keyof T]]): R;

I think that it should be toContainEntry(entry: [keyof T, T[keyof T]]): R;
( The Expect interface on the other hand is correct. )

This is the source code

Given that testing property of T (TActual) - key should come from that T, not some other T.

export default {
  toContainEntry: (actual, expected) => {
    const pass = predicate(actual, expected);
    /*
        predicate code
        export default (obj, [key, value]) => obj.hasOwnProperty && obj.hasOwnProperty(key) && equals(obj[key], value);
    */
    if (pass) {
      return { pass: true, message: passMessage(actual, expected) };
    }

    return { pass: false, message: failMessage(actual, expected) };
  }
};

predicate.js

export default (obj, [key, value]) => obj.hasOwnProperty && obj.hasOwnProperty(key) && equals(obj[key], value);

@mattphillips
Given that Matchers are used for the return type of expect and expect is typed as :

<T = any>(actual: T): JestMatchers<T>;
type JestMatchers<T> = JestMatchersShape<Matchers<void, T>, Matchers<Promise<void>, T>>;

T should default to type any rather than {}.

Was this page helpful?
0 / 5 - 0 ratings