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

TypeScript should not give "is not assignable" errors in t.deepEqual #2403

Closed
mesqueeb opened this issue Feb 17, 2020 · 3 comments
Closed

TypeScript should not give "is not assignable" errors in t.deepEqual #2403

mesqueeb opened this issue Feb 17, 2020 · 3 comments

Comments

@mesqueeb
Copy link
Contributor

mesqueeb commented Feb 17, 2020

Please provide details about:

What you're trying to do

I have a merge library that works like a "deep" Object.assign, and also returns a "merged interface" for the objects merged.

I'm writing tests with TypeScript as well -- .ts files. In the tests I merge objects and then check the results with deepEqual.

What happened

TypeScript is giving me errors like these inside the deepEqual function:

image

While if you compare what I pass with the res object I'm actually comparing it to:

image

You can see that body.head is a boolean, so I don't see why such an error is occurring, my types are correct.

What you expected to happen

I don't expect TypeScript to give errors when doing a deepEqual check.

I think deepEqual shouldn't do any type checks at all. And if it does, it should just compare the types of the first param, to the second param. Which in my case are exactly the same types, so I don't understand why I'm getting errors.

Reproduction

Please share relevant sample code. Or better yet, provide a link to a minimal reproducible example.

My tiny "merge" util is this repo: merge-anything.

It only has a few test files and you can see I had to put them full of // @ts-ignore to be able to work around this problem:
https://github.com/mesqueeb/merge-anything/blob/master/test/index.ts#L23

You can reproduce it by cloning the repo and doing:

  • npm i && npm run test

Ava config

We'll also need your AVA configuration (in package.json or ava.config.* configuration files) and how you're invoking AVA. Share the installed AVA version (get it by running npx ava --version).

ava config in package.json:
https://github.com/mesqueeb/merge-anything/blob/master/package.json#L63

@novemberborn
Copy link
Member

I think deepEqual shouldn't do any type checks at all. And if it does, it should just compare the types of the first param, to the second param. Which in my case are exactly the same types, so I don't understand why I'm getting errors.

That's what deepEqual does. This looks like a TypeScript issue to me. Cast both sides to unknown and call it a day 😄

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

@mesqueeb
Copy link
Contributor Author

Hi @novemberborn I guess I'm confused why this is happening, and I feel that a lot of TS developers who write ava tests in TS will face this problem.

Do you know why the second param in deepEqual is checking/comparing its type not with the first param, but instead with a completely different object?

@novemberborn
Copy link
Member

I guess I'm confused why this is happening, and I feel that a lot of TS developers who write ava tests in TS will face this problem.

But it's a TypeScript problem, not an AVA problem.

Do you know why the second param in deepEqual is checking/comparing its type not with the first param, but instead with a completely different object?

In the image you shared above, I'm assuming the tooltip is the inferred type of res? That's clearly a different type than what you're comparing against. But the problem is in the type inference, not AVA.

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

No branches or pull requests

2 participants