-
Notifications
You must be signed in to change notification settings - Fork 12.8k
never doesn't equal never when never is keys/values from filtering generic object wrapped inside another object by exact value #51145
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
Comments
This definition of Using a more straightforward definition type Equals<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false; this works as expected, though the more-compact form doesn't for some reason: // Doesn't work
type Equals<A, B> = [A, B] extends [B, A] ? true : false; |
@RyanCavanaugh That particular definition of Explanation here: |
Yep, this is a fairly popular type - it allows one to easily check if a type is It also comes with a funny behavior related to structurally equivalent intersections: And I suspect that this sort-of thing is responsible for the issue here. Even though the type gets reduced~ to This issue looks quite similar to what I've reported in the past (issue) and what got fixed here. However, I've confirmed that the issue is not the same and while my issue was a regression in 4.4, this one here didn't work before that. |
The fact that it still repros on the tuple form is pretty interesting, since that should be going through the normal relational path. Though I wonder if the first thing that gets checked is the index signature between the two types. |
This is quite interesting! We have 3 different
We also have 2 different implementations of the filtering mapped type:
I don't intend to explore all combinations of those 2 sets but I will mention particular variants from both of those. nested Equals + any-valueThis one works correctly: TS playground
short Equals + any valueThis one doesn't work correctly: TS playground
short Equals + indexed access valueThis one works correctly: TS playground It's kinda interesting because almost everything here is the same as in the variant described above. However, in here checking the assignability of the permissive intantiations returns a different result despite the fact that we seamingly compare the same types ( So why is that? In here, the Note: it would be kinda nice if the wildcard type would get printed as identity-based Equals + any valueThis one doesn't work correctly: TS playground This is fairly similar to the "short Equals + any value" case. The only difference here is what permissive instantiations we are comparing here for |
It doesn't work well. In export type Equal<A, B, Then = true, Else = false> = [A, B] extends [B, A]
? And<IsAny<A>, IsAny<B>, Then, Or<IsAny<A>, IsAny<B>, Else, Then>>
: Else This version checks against btw UPDATE: type R = Equal<[number], [any]> // false 🤦 |
Yep, this was fixed here (in response to this very issue here) |
Bug Report
🔎 Search Terms
never equals filter mapped type
🕗 Version & Regression Information
It's broken in all tested versions of typescript (4.1.5 until 4.9.0-dev.20221011 in TS playground). Versions prior 4.1.5 do not support mapped types keys filtering.
⏯ Playground Link
Playground minimal code
Playground both keyof and of Values<> cases
💻 Code
So wee need to:
O
, in an object(i.e{anyKey: O}
or just[O]
).Equals<>
in such a way to pass further empty object.never
will be passed.Equals<>
🙁 Actual behavior
filteredValuesMatchNever
is false🙂 Expected behavior
filteredValuesMatchNever
must be true.Actually with the
FilterByStringValue
rewritten like this:filteredValuesMatchNever
somehow becomes trueThe text was updated successfully, but these errors were encountered: