Skip to content

Type narrowing over x does not reflect in a statement of the format false && x #44156

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
awalgarg opened this issue May 19, 2021 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@awalgarg
Copy link

awalgarg commented May 19, 2021

Bug Report

πŸ”Ž Search Terms

type narrowing, object is possibly undefined, false &&

πŸ•— Version & Regression Information

4.3 - nightly

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function foo1(x?: string) {
  if (!x) {
    return;
  }

  x.toString(); // fine
  true && x.toString(); // fine
  false && x.toString(); // Object is possibly undefined
  0 && x.toString(); // fine!
}

πŸ™ Actual behavior

x is not narrowed from undefined | string to string in false && x.toString().

πŸ™‚ Expected behavior

x is narrowed from undefined | string to string in false && x.toString().

@MartinJohns
Copy link
Contributor

Most likely a duplicate of #26914.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 19, 2021
@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

4 participants