Skip to content

Nullish coalescing assignment operator doesn't work correctly with logical operators #48473

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

Closed
cshaa opened this issue Mar 29, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@cshaa
Copy link

cshaa commented Mar 29, 2022

Bug Report

Using the nullish coalescing assignment operator ??= on a logical statement which contains a logical operator (&& or ||) fails to narrow the type, even though using the nullish coalescing operator ?? works correctly.

declare function acceptBoolean (s: boolean): void
declare let x: boolean | null, y: boolean | null;

x = x ?? (4 < 3 && 3 < 4);
acceptBoolean(x); // narrowed correctly

y ??= 4 < 3 && 3 < 4;
acceptBoolean(y); // error

Playground.

  • TypeScript version 4.6.2

Probably related to: #40359, #40494, #44988 #42203

@cshaa cshaa changed the title Nullish coalescing assignment operator doesn't work correctly, again Nullish coalescing assignment operator doesn't work correctly with logical operators Mar 29, 2022
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 29, 2022
@RyanCavanaugh
Copy link
Member

This looks identical to #40359 actually

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants