Skip to content

update contextual discrimination to include omitted members - #43633

Merged
Wesley Wigham (weswigham) merged 1 commit into
microsoft:masterfrom
erikbrinkman:omitted-discriminated-union
Apr 24, 2021
Merged

update contextual discrimination to include omitted members#43633
Wesley Wigham (weswigham) merged 1 commit into
microsoft:masterfrom
erikbrinkman:omitted-discriminated-union

Conversation

@erikbrinkman

Copy link
Copy Markdown
Contributor

This diff extends the types checked by discriminateContextualTypeByObjectMembers and discriminateContextualTypeByJSXAttributes to also include any optional components in the type union.

fixes#41759 although it doesn't address the better error reporting for their last repro, which I'm not sure how to address.

@ghost

Deleted user (ghost) commented Apr 10, 2021

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

Comment threadsrc/compiler/checker.ts Outdated
Comment threadsrc/compiler/checker.ts Outdated
This diff extends the types checked by
discriminateContextualTypeByObjectMembers and
discriminateContextualTypeByJSXAttributes to also include any optional
components in the type union.
fixes#41759 although it doesn't address the better error reporting for
their last repro, which I'm not sure how to address.
@erikbrinkman

Copy link
Copy Markdown
ContributorAuthor

Wesley Wigham (@weswigham) that check makes sense. It should be resolved, although I had trouble accepting the changes through gh. Thanks for the pointers of where to start btw, probably wouldn't have thrown this together without them.

@schmod

Andrew Schmadel (schmod) commented May 4, 2021

Copy link
Copy Markdown

Under the TS 4.3 beta, this change appears to have introduced a stack overflow in my codebase:

RangeError: Maximum call stack size exceeded
at checkIdentifier (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:55295:26)
at checkExpressionWorker (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:61948:28)
at checkExpression (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:61903:38)
at checkNonNullExpression (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:57527:37)
at checkPropertyAccessExpression (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:57572:85)
at checkExpressionWorker (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:61977:28)
at checkExpression (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:61903:38)
at getTypeOfExpression (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:61857:24)
at getMatchingUnionConstituentForObjectLiteral (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:53649:40)
at discriminateContextualTypeByObjectMembers (/Users/andrew/code/repo_name/node_modules/typescript/lib/tsc.js:56277:20)

@erikbrinkman

Copy link
Copy Markdown
ContributorAuthor

Andrew Schmadel (@schmod) can you provide more context? Ideally a minimum working example, and even more ideally a bisect showing it was this commit? The call stack seems to indicate that it's causing a stack overflow at getMatchingUnionConstituentForObjectLiteral which is called before this commit's change to discriminateContextualTypeByObjectMembers .

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Fix AvailableA PR has been opened for this issueFor Backlog BugPRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Omitted property does not narrow discriminated union contextual type

5 participants

@erikbrinkman@schmod@weswigham@sandersn@typescript-bot