-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixed excess and common property checks with NoInfer
#57673
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
Fixed excess and common property checks with NoInfer
#57673
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
aa83f78
to
bcbd419
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, but would prefer to erase all substitution types as I suggest.
src/compiler/checker.ts
Outdated
@@ -23756,6 +23756,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
return resolved.callSignatures.length === 0 && resolved.constructSignatures.length === 0 && resolved.indexInfos.length === 0 && | |||
resolved.properties.length > 0 && every(resolved.properties, p => !!(p.flags & SymbolFlags.Optional)); | |||
} | |||
if (isNoInferType(type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to erase all substitution types (to their base types) instead of just NoInfer
types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed out the requested change but without any new tests.
I've tried a bunch of things based on my intuition in an attempt to write some tests for this change and nothing - from my attempts - managed to hit those lines with a non-NoInfer substitution type. So I went to recheck if I could observe some cases like this using the existing test suite:
isExcessPropertyCheckTarget
/isKnownProperty
didn't observe such substitution types at allisWeakType
has observed it indeeplyNestedMappedTypes
andconditionalTypeDoesntSpinForever
. Those are complex enough that figuring out a test case based solely on them might take me a longer moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's not going to be easy to come up with a case where it matters and I'm fine going without.
This PR was not up to date with main and broke baselines. |
Argh! |
I figured out that it might be better to handle
NoInfer
at those levels because there is always a risk thatisWeakType
/isKnownProperty
might get called outside of thecheckTypeRelatedTo
.However, this could potentially also be fixed within
getNormalizedType
- I briefly took a look at this possible solution and it felt like it could be slightly more complicated and that it could potentially result in potential gotchas. Normally, each constituent gets normalized while the type gets broken down in the relationship check - not when the union/intersection gets first observed by it. In fact, at one moment in time normalization for intersection members was introduced by #49119 and then partially reverted in #50535 (the logic got adjusted to only normalize intersections containing{}
).If you think that it's a wrong judgement call - please let me know and I'll adjust the PR to put this logic into
getNormalizedType
. There is also a risk that normalization earlier could fix some other things. For the most part those other things are likely working correctly already because those types get normalized - just later on.fixes #57697