jest-matcher-deep-close-to icon indicating copy to clipboard operation
jest-matcher-deep-close-to copied to clipboard

Accept typed objects

Open petrusek opened this issue 3 years ago • 1 comments

Hi, I had a typescript issue using this matcher with named interface types like

interface Point {
  x: number;
  y: number;
}

The error is (with typescript v4.4.3):

Argument of type 'Point' is not assignable to parameter of type 'Iterable'.
  Type 'Point' is not assignable to type 'IterableObject'.
    Index signature for type 'string' is missing in type 'Point'.ts(2345)

If the type information is removed, everything works OK. So when I checked, I've seen there are more runtime type checks (in recursiveCheck) so maybe the typing could be relaxed a bit to allow this scenario. Unfortunately I couldn't come up with a better solution than just allowing the exact type coming from expect(value: T) ... which I think if the user would use, it should be most of the time correct.

I hope this solution is acceptable (or somebody could improve it). Thanks.

petrusek avatar Oct 19 '21 19:10 petrusek

Looks like a nice proposal ... any updates?

Should we update documentation as well?

brody4hire avatar Dec 03 '21 00:12 brody4hire