-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 contextual discrimination for omitted members #43937
Fix contextual discrimination for omitted members #43937
Conversation
In short, the fix I submitted looked at the union ofproperties, but it really should have looked at the intersection. Two sytlistic notes. I couldn't find the best way to get the unique strings of an array like `[...new Set()]` would, so I created a small helper function, but didn't put it in a great place. Also, before the second concatenated array of discriminators at least matched the first in complexity, but now it's much worse. I don't think that section is particularly easy to read, but I also don't see a significantly reusable part. fixes #41759
I'm not sure how to interact with typescript bot, but the previous PR seems to have introduced a stack overflow, which should be addressed at least in tandem with this fix. |
Hey @weswigham , the one user who reported a stack overflow hasn't followed up to debug, so I'm hoping it's a non issue. I don't love the style of this code, primarily because it's not clear how best to utilize sets in |
* upstream/main: (473 commits) Correct node used for isDefinition calculation (microsoft#48499) fix(48405): emit dummy members from a mapped type (microsoft#48481) CFA for dependent parameters typed by generic constraints (microsoft#48411) No contextual typing from return types for boolean literals (microsoft#48380) fix(47733): omit JSDoc comment template suggestion on node with existing JSDoc (microsoft#47748) Ensure that we copy empty NodeArrays during transform (microsoft#48490) Add a new compiler option `moduleSuffixes` to expand the node module resolver's search algorithm (microsoft#48189) feat(27615): Add missing member fix should work for type literals (microsoft#47212) Add label details to completion entry (microsoft#48429) Enable method signature completion for object literals (microsoft#48168) Fix string literal completions when a partially-typed string fixes inference to a type parameter (microsoft#48410) fix(48445): show errors on type-only import/export specifiers in JavaScript files (microsoft#48449) Fix newline inserted in empty block at end of formatting range (microsoft#48463) Prevent looking up symbol for as const from triggering an error (microsoft#48464) Revise accessor resolution logic and error reporting (microsoft#48459) fix(48166): skip checking module.exports in a truthiness call expression (microsoft#48337) LEGO: Merge pull request 48450 LEGO: Merge pull request 48436 fix(48031): show circularity error for self referential get accessor annotations (microsoft#48050) Revert "Fix contextual discrimination for omitted members (microsoft#43937)" (microsoft#48426) ...
In my original PR #43633, choices for optional properties that could be discriminatory were chosen from the union type, which in turn meant that the possible omitted properties to check for discrimination was taken from the intersection of properties across all types. This is the incorrect way to check, when it's actually the union of all properties that should be checked for discrimination. See the additions to the tests for details.
Two stylistic notes about this PR. In principle the code should be going from intersection to union, but it proved more difficult to do given the current functions I found available. As a result:
[...new Set()]
would, so I created a small helper function, but didn't put it in a great place. Given the lack of documentation in checker, I'm not sure where to put it, or if there are better utilities I can use to achieve the same effect.Given your initial suggestions and the review of the past PR, @weswigham seems poised to review this the quickest.
Fixes #41759