GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix contextual discrimination for omitted members by erikbrinkman · Pull Request #43937 · microsoft/TypeScript

Conversation

@erikbrinkman

@erikbrinkman Erik Brinkman (erikbrinkman) commented May 4, 2021

Copy link
Copy Markdown
Contributor

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:

  1. 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. 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.
  2. This function was relatively hard to parse before. Arguably the first PR didn't help, but it kept it at roughly the same complexity. This PR makes it much worse. Ideally I'd like to strip out some common functionality, or decompose the nested loops, but from looking through checker that seems less the preferred style. Basically, this works, but I don't love it, and feedback is welcome.

Given your initial suggestions and the review of the past PR, Wesley Wigham (@weswigham) seems poised to review this the quickest.

Fixes #41759

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@erikbrinkman
Fix contextual discrimination for omitted members
8b3588d
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
@typescript-bot TypeScript Bot (typescript-bot) added the For Backlog Bug PRs that fix a backlog bug label May 4, 2021
@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) requested a review from Wesley Wigham (weswigham) May 4, 2021 16:16
@erikbrinkman

Erik Brinkman (erikbrinkman) commented May 4, 2021

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sandersn Nathan Shively-Sanders (sandersn) assigned Wesley Wigham (weswigham) May 13, 2021
@erikbrinkman

Erik Brinkman (erikbrinkman) commented Jul 11, 2021

Copy link
Copy Markdown
Contributor Author

Hey Wesley Wigham (@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 checker.ts, or when it's reasonable to factor out functions, or where to put utilities like uniqueStrings. Any general comments you have on this, or the meat of the commit would be much appreciated.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham
Wesley Wigham (weswigham) merged commit 751c114 into microsoft:main Mar 4, 2022
@erikbrinkman
Erik Brinkman (erikbrinkman) deleted the fix-contextual-discrimination-for-omitted-members branch March 4, 2022 22:11
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Mar 16, 2022

Copy link
Copy Markdown
Member

This PR seems to have regressed our check times on material UI drastically.

image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Mar 16, 2022
Investigate recent regression on Material UI from contextual discrimination changes #48298
Closed
Andrew Casey (amcasey) added a commit to amcasey/TypeScript that referenced this pull request Mar 25, 2022
@amcasey
Revert "Fix contextual discrimination for omitted members (microsoft#…
07a6845
…43937)"

This reverts commit 751c114, which caused check time for our MUI benchmark to increase by ~25%.
Andrew Casey (amcasey) added a commit that referenced this pull request Mar 25, 2022
@amcasey
Revert "Fix contextual discrimination for omitted members (#43937)" (#…
e742625
…48426)

This reverts commit 751c114, which caused check time for our MUI benchmark to increase by ~25%.
Sidharth Vinod (sidharthv96) added a commit to sidharthv96/TypeScript that referenced this pull request Apr 1, 2022
@sidharthv96
Merge remote-tracking branch 'upstream/main' into fix/46149
e149cc3
* 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)
  ...
@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request Apr 28, 2022
Omitted property does not narrow discriminated union contextual type #41759
Closed
@nebkat Nebojša Cvetković (nebkat) mentioned this pull request Jun 4, 2023
String constant fails to infer type inside nested unions #54498
Closed
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@weswigham Wesley Wigham (weswigham) Awaiting requested review from weswigham

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@weswigham Wesley Wigham (weswigham)

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

PR Backlog
Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Omitted property does not narrow discriminated union contextual type

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@erikbrinkman @DanielRosenwasser @weswigham @typescript-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.