Skip to content
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

Merged

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Mar 7, 2024

I figured out that it might be better to handle NoInfer at those levels because there is always a risk that isWeakType/isKnownProperty might get called outside of the checkTypeRelatedTo.

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

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 7, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@Andarist Andarist force-pushed the fix/excess-n-common-checks-noinfer branch from aa83f78 to bcbd419 Compare March 8, 2024 19:59
@sandersn sandersn added this to Not started in PR Backlog Mar 18, 2024
@sandersn sandersn moved this from Not started to Waiting on reviewers in PR Backlog Mar 20, 2024
Copy link
Member

@ahejlsberg ahejlsberg left a 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.

@@ -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)) {
Copy link
Member

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.

Copy link
Contributor Author

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 all
  • isWeakType has observed it in deeplyNestedMappedTypes and conditionalTypeDoesntSpinForever. Those are complex enough that figuring out a test case based solely on them might take me a longer moment.

Copy link
Member

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.

PR Backlog automation moved this from Waiting on reviewers to Needs merge Mar 20, 2024
@ahejlsberg ahejlsberg merged commit 520772e into microsoft:main Apr 2, 2024
25 checks passed
PR Backlog automation moved this from Needs merge to Done Apr 2, 2024
@jakebailey
Copy link
Member

This PR was not up to date with main and broke baselines.

@ahejlsberg
Copy link
Member

Argh!

@Andarist Andarist deleted the fix/excess-n-common-checks-noinfer branch April 2, 2024 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

Excess and common property checks don't work correctly with NoInfer
4 participants