-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
change deepEqual (actual: ValueType, expected: ValueType) to (any, any) #2580
Comments
Makes sense to me. However, I think it should be |
For me this makes code analysis less reliable. It makes sense that you should compare objects with the same types, otherwise they are not equal anyway. |
This might be similar to what @papb was bringing up in #2575. I'm reluctant though, the expected value should be structurally the same as the actual value, and it's nice to get auto-completion and type checking for it. What I tend to do when I get stuck with the type inference in tests is cast to |
Hi @novemberborn, I totally agree with you. I wouldn't like to lose autocompletion and type safety on this. When I want to assert that two things are deep equal, if TypeScript can know ahead of time that they don't even have the same time, I prefer it to fail at compile time than at runtime. |
Hi @mesqueeb, can you post a minimal example that represents your situation in which the types "are the same" but TypeScript thinks they are not? I couldn't understand only from your screenshots. To me, if two objects don't have the same type, then clearly |
For #2456 I'm changing this to: <Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected; |
ava/index.d.ts
Line 125 in f328a69
Because I run my Ava tests in ts-node, Ava has type checking on assertion functions.
Mostly it's OK, but the type checking done by
deepEqual
always gets in the way.There are so many cases where the the two objects I'm comparing are practically the same data-wise, but Type-wise the type of one is not the same as the other.
Just one example:
![image](https://user-images.githubusercontent.com/3253920/93077790-4fbc8800-f6c4-11ea-8524-38b1480cf2a8.png)
Or another:
![image](https://user-images.githubusercontent.com/3253920/93078038-bc378700-f6c4-11ea-9205-5038f4331376.png)
You can see the types being passed are clearly the same, but somehow
![image](https://user-images.githubusercontent.com/3253920/93078103-da04ec00-f6c4-11ea-9235-48770fbca279.png)
DeepEqualAssertion
is throwing errors:I believe TypeScript works best if it doesn't get in the way, and one way to solve a lot of issues I always face with
deepEqual
is to just simply change the function's signature to:I don't see any harm in this and I believe that we don't need the currently strict type checks there are in place on
deepEqual
. Why don't we letdeepEqual
be only about checking the data, not the types. That's my humble request. 🙃The text was updated successfully, but these errors were encountered: