-
Notifications
You must be signed in to change notification settings - Fork 12.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
Using this-type with intersection type makes it possible to simulate HKT #40928
Comments
Related to #1213 |
Simpler version of the question: interface A {
a: string;
getA: this['a'];
}
// Should T be 'never' or 'string'?
type T = (A & { a: number })['getA'];
I don’t really know the answer to this question. I can’t find an instance of this in our test suite, so perhaps in some trivial way, the answer is no. But I would not be surprised if this behavior was intentional. It looks like it could be important for some mixin patterns, for example. |
@DanielRosenwasser agrees that this is probably intentional 😄 |
Thx for the work :) |
TypeScript Version: Lastly tested in v4.1.0-dev20201003, but this has been existing at least since v3.8
Search Terms: this-type, this type, intersection, HKT, higher kinded type
Code
Expected behavior: I expected that reduction of
this
type doesn't depends on type that is intersected with.Actual behavior: reduction of
this
type depends on type that is intersected with.The actual behavior makes sense to me(at least). It's not hard to accept its behavior. However, It looks like unintended behavior or bug (just like recursive conditional type before) so that I can't certain it's okay to use this. Is this idea safe to use?
Playground Link
The text was updated successfully, but these errors were encountered: