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

Accept typed objects #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

petrusek
Copy link

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.

interface Matchers<R> {
toBeDeepCloseTo: (expected: Iterable, decimals?: number) => R;
toMatchCloseTo: (expected: Iterable, decimals?: number) => R;
interface Matchers<R, T> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could T be optional here?

@brodycj
Copy link

brodycj commented Dec 3, 2021

Looks like a nice proposal ... any updates?

Should we update documentation as well?

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

Successfully merging this pull request may close these issues.

2 participants