-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Problem with function types, <T>() => T extends X ? () : () #56721
Comments
Where are people getting this definition of |
Probably originally from #27024 (comment) and then from sindresorhus/type-fest after that? |
Context: This variant allows for distinguishing |
I got it from https://github.com/type-challenges/type-challenges/blob/main/utils/index.d.ts |
@fatcerebus
What is amounts to is that the "correct" answer(s) to a type function "Equals(A,B)" depends on what it is being used for. In particular, the types Therefore exporting these intrinsic type functions
would enable the users to handle the corner cases as they need, and simply apply |
@craigphicks Thatβs all true, but TS doesnβt add new pack-in utility types (intrinsic or otherwise) unless needed for declaration emit, so we have to work with what we have. |
If that in order not to pollute the global namespace? That's legit, but using a namespace (e.g. |
The reason for not adding utility types is that whatever definition we choose will invariably not match what 30% (minimum) of people expect to happen w.r.t how they treat any, whether they distribute over unions, how they treat |
It seems like we're using the strict subtype relation in one case, and regular assignability in the other. I don't even know which people are wanting with this definition of I'd really encourage everyone to just use something like type Equals<X, Y> = [X] extends [Y] ? [Y] extends [X] ? true: false; if they're not actively trying to probe the strangest corners of the type system π΅βπ« |
The intent of this definition of |
π Search Terms
"function", "generic function"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAYgdgHgBoD4oF4oICooBQCUGa2UEAHsBHACYDOUSUA-FAIxQBcUATAFChIUAKIBHAK4BDADZ02yADRQAmmnR8osRKjKVq9DVoSqWUYACdx0bgDMZdCHwHhoAdXMB7OAHMAShDpxaWAMEQl7eQBvcwhJGi9pEChJbgByAEFUgF8lSJSoDOyUJydBaHh5HUwcfCJ0El0qWgYmVg5ufjKtHmQ1LFxCYihSCib6RlN23mchMSlZHqQlE3VNCt7G-TpDeB6TVgsrLig7WUcZ6ABhD3MYgGNgf0Dg0Ln7HujY+LhE5LTMnJQPL-IpAA
π» Code
π Actual behavior
type A should shows true.
π Expected behavior
type A should be false.
It works well when the code is like this.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: