You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
While if you compare what I pass with the res object I'm actually comparing it to:
You can see that body.headis 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.
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).
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.)
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.
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 withdeepEqual
.What happened
TypeScript is giving me errors like these inside the
deepEqual
function:While if you compare what I pass with the
res
object I'm actually comparing it to: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
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
ava config in package.json:
https://github.com/mesqueeb/merge-anything/blob/master/package.json#L63
The text was updated successfully, but these errors were encountered: