-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Infer operator returning container type instead of applied generic #48772
Comments
Bisected to #42284 |
If you keep substituting in the expansions of each type and see the operation being performed, this is a correct inference -- as in many cases, there are multiple equally correct inferences that can be made, and as a result of the linked PR we switched from a certain correct inference to a different correct inference. In general it's not safe to assume that inferring onto a |
Thanks for the quick reply! I can appreciate how this is a correct inference, but it's certainly surprising. I'm sure a case exists, but I'm having a hard time imaging a time where I'd want the current result. I guess it's partially surprising because I wrote |
Yeah, inference is structural, not nominal, so the type system is always working backwards from the output of the generic to figure out what should go in the
I'm not a TypeScript team member, but from what I do know about how the type system works I'm going to say probably not - in many cases the compiler doesn't even know which type alias a type came from, so |
Nothing's impossible but in general we're not keen to spend time tweaking things in the grey areas of inference - there are always going to be cases where there's a structural inference going on here, so making 6 out of 10 cases work as opposed to 4 out of 10 cases doesn't really change the situation much. |
Thanks, I was missing this context and it explains why this is so difficult.
That's reasonable and I understand why the team takes that position. I'll close this issue, thanks for you time. |
@dpchamps came up with a good solution to my problem that I'll post here for others. Instead of inferring the generic, we can omit the keys in |
Bug Report
π Search Terms
infer, conditional type, generic, alias
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
I expected
ExtractedAdditionalContext
to beAdditionalContext
or{ customValue: string }
, and fortest1
to compile without error.π Expected behavior
ExtractedAdditionalContext
isAdditionalContext & BaseContext<Config>
which is the same type asContext
.test1
results in a compiler error of:Additional notes
When I remove the
config
property fromBaseContext
the issue is resolved.The text was updated successfully, but these errors were encountered: