-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Common properties check:Fix intersection-parent check #34646
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
Conversation
I'd like some commentary from others on the approach before I clean this up. |
I updated a failing baseline, which I believe is correct. I can't tell if it's desirable but I suspect not: export function myHigherOrderComponent<P>(Inner: React.ComponentClass<P & {name: string}>, props: Readonly<P>) {
<Inner {...props} name="Matt"/>;
~~~~~
!!! error TS2326: Types of property 'name' are incompatible.
!!! error TS2326: Type '"Matt"' is not assignable to type 'P["name"] & string'.
!!! error TS2326: Type '"Matt"' is not assignable to type 'P["name"]'.
} The error comes from assigning
Previously the common property check was skipped, correctly, for all constituents of the target. The whole-intersection check was also skipped, incorrectly, since the whole intersection was not a weak type because of However, now that the constituents record when they skip a common property check, the whole-intersection check runs and checks that the four properties of the target are assignable from the source. This is true for As far as I can tell, this hole is required for React HOCs to compile, because the error seems correct to me. |
isIntersectionConstituent controls whether relation checking performs excess property and common property checks. It is possible to fail a relation check with excess property checks turned on, cache the result, and then skip a relation check with excess property checks that would have succeeded. #33133 provides an example of such a program. Fixes #33133 the right way, so I reverted the fix at #33213 Fixes #34762 (by reverting #33213) Fixes #33944 -- I added the test from #34646
#34789 is a better fix |
* Add isIntersectionConstituent to relation key isIntersectionConstituent controls whether relation checking performs excess property and common property checks. It is possible to fail a relation check with excess property checks turned on, cache the result, and then skip a relation check with excess property checks that would have succeeded. #33133 provides an example of such a program. Fixes #33133 the right way, so I reverted the fix at #33213 Fixes #34762 (by reverting #33213) Fixes #33944 -- I added the test from #34646 * Update comments in test
Component commits: 2e0b451 Add isIntersectionConstituent to relation key isIntersectionConstituent controls whether relation checking performs excess property and common property checks. It is possible to fail a relation check with excess property checks turned on, cache the result, and then skip a relation check with excess property checks that would have succeeded. microsoft#33133 provides an example of such a program. Fixes microsoft#33133 the right way, so I reverted the fix at microsoft#33213 Fixes microsoft#34762 (by reverting microsoft#33213) Fixes microsoft#33944 -- I added the test from microsoft#34646 14d7a44 Merge branch 'master' into add-isIntersectionConstituent-to-relation-key ea80362 Update comments in test 0764275 Merge branch 'master' into add-isIntersectionConstituent-to-relation-key
Component commits: 2e0b451 Add isIntersectionConstituent to relation key isIntersectionConstituent controls whether relation checking performs excess property and common property checks. It is possible to fail a relation check with excess property checks turned on, cache the result, and then skip a relation check with excess property checks that would have succeeded. #33133 provides an example of such a program. Fixes #33133 the right way, so I reverted the fix at #33213 Fixes #34762 (by reverting #33213) Fixes #33944 -- I added the test from #34646 14d7a44 Merge branch 'master' into add-isIntersectionConstituent-to-relation-key ea80362 Update comments in test 0764275 Merge branch 'master' into add-isIntersectionConstituent-to-relation-key
@sandersn should this be closed now? |
The check for common properties ("weak type check") when the target is an intersection is supposed to skip the common property check for constituents and instead check assignability of properties for the entire type. The current code correctly skips the check for constituents, but fails to check the whole intersection sometimes. That's because the whole-intersection check uses
isPerformingCommonPropertyChecks
, but that reports the state of the intersection itself, not its constituents.This PR changes the boolean flag
isApparentIntersectionConstituent
to a box,{ skipped: boolean }
, that lets children report whether they skipped the common property check or not.The meat of the PR is in the first page or so; everything else is just changing the type of isApparentIntersection.
This PR is not done:
And I don't attempt to fix known problems with the existing approach, like the caching problem or the fact that source intersections also have their children skip common property checks.
Fixes #33944