-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix(types): fixed Fixtures
type to disambiguite between intersected mapped types
#33782
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
I ran a different set of tests locally and missed this before opening the PR. I'll look into the reported failure soon. FWIW, the failures are related to this piece of code: playwright/tests/playwright-test/types.spec.ts Lines 110 to 117 in f3ae940
|
Thank you for the PR, this looks fantastic!
I applied your suggestion to replace |
@dgozman I already included the constraint fix here too :) not in as many places though, I chose to be conservative with my change |
Test results for "tests 1"9 failed 2 flaky37163 passed, 650 skipped Merge workflow run. |
Per the linked issue, this only works if downstream users use TS 5.6+, right? |
Yes. I don't think there is a suitable way to rewrite those types that would support older TS versions. One idea to rewrite this would be to avoid reverse mapped type inference here somehow while preserving the contextual typing capabilities. Having that inference here isn't particularly desired and it doesn't quite work today anyway in this case. |
I came up with this beautiful hack that makes it work: TS playground. Further testing would be required to make sure that it doesn't break anything but it looks really promising to me. The idea behind this workaround is that properties of remapping mapped types don't contribute to contextual typing. This matches the pre-5.7 behavior for this particular scenario. So by ensuring that our |
@Andarist Let me play a bit with this beautiful hack 😄 That said, we have to support at least TypeScript 5.0, so I'd prefer to avoid |
I mean,
It turns out that I confused myself here altogether. Both It's correct to say that All of this works based on subtle fact that you have this mix of known/resolved properties with properties of a type that is still generic. In such an intersection case, TS (before 5.7) would just ignore the generic mapped part of the intersection when providing a contextual type and would only use the more "concrete" part of the type. This wasn't consistent because in non-intersection cases it wouldn't ignore the generic mapped part at all, it would use it. Fixing that had an unfortunate effect of breaking your types. But at the same time, it means that it doesn't quite matter how you write those generic mapped types here... because pre TS 5.7 they will just be ignored when selecting the contextual type. |
fixes #33763
context behind the change can be found here: microsoft/TypeScript#60619 (comment)
cc @dgozman