Skip to content
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

Defer checking subexpressions of binary expressions with known boolean result type #60865

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

fixes #60130

This PR removes the mechanism introduced in #54380 in favor of using the older checkDeferredNode mechanism that allows the compiler to avoid an extra set of redundant errors.

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Dec 28, 2024
// Those boolean arguments wouldn't even have to be viable sources for type arguments being inferred.
//
// For those reasons, we defer obtaining the operand types here and checking the related errors.
checkNodeDeferred(node);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really the core of the fix. The rest of the PR only moves code around (for the most part)

state.skip = true;
setLastResult(state, booleanType);
break;
case SyntaxKind.QuestionQuestionToken:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity (this may be a dumb question): Since SyntaxKind.EqualsToken (which I assume refers to assignment) is handled above and SyntaxKind.QuestionQuestionToken is handled here, should nullish coalescing assignment (SyntaxKind.QuestionQuestionEqualsToken) also be handled here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a valid question. I think no adjustments have to be made here though. Only = is permitted when the left side is a destructuring pattern. Other kinds of assignment~ operators in such scenarios result in a syntax error:

let a: number | undefined;
({ a } ??= { a: 10 }); // Uncaught SyntaxError: Invalid left-hand side in assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Assertion signature on generics doesn't narrow
3 participants