Skip to content

infer from usages: support short-circuiting assignment operators #52860

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

Merged

Conversation

zardoy
Copy link
Contributor

@zardoy zardoy commented Feb 19, 2023

This case is supported:

let x

if (x === undefined || x === null) x = 1
if (!x) x = "2"
if (x) x = true

So why don't support this:

let x

x ??= 1
x ||= "2"
x &&= true

TypeScript docs

Real world pattern:

let x

function workWithX() {
  // init lazily
  x ??= ...
}

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Feb 19, 2023
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@sandersn sandersn assigned iisaduan and sandersn and unassigned iisaduan and sandersn Feb 28, 2023
@sandersn
Copy link
Member

That makes sense to me.
Next time please open a bug for your idea first, though.

@iisaduan iisaduan merged commit a97ba98 into microsoft:main Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants