Skip to content

null checks not working with &&false #52530

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
whizsid opened this issue Jan 31, 2023 · 2 comments
Closed

null checks not working with &&false #52530

whizsid opened this issue Jan 31, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@whizsid
Copy link

whizsid commented Jan 31, 2023

Bug Report

I have a project that enabled allowUnreachableCode option. I wanted to bypass a large condition. So I appended &&false at the end of the condition. But now I can not compile the project due to null check errors.

🔎 Search Terms

  • null check false
  • null check boolean
  • null guard boolean

⏯ Playground Link

Playground link with relevant code

💻 Code

let anExampleVariable: string|null = "Hello World"

if(anExampleVariable!=null&&false) {
    let anotherVariable: string = anExampleVariable;
    //   ^^^^^^^^^^^^^^^ Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.
}

🙁 Actual behavior

Getting Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'. error.

🙂 Expected behavior

null checks should work as before.

@MartinJohns
Copy link
Contributor

Duplicate of #26914.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 1, 2023
@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