Skip to content

Incorrect Report that an Object may be null #43537

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
legodude17 opened this issue Apr 5, 2021 · 3 comments
Closed

Incorrect Report that an Object may be null #43537

legodude17 opened this issue Apr 5, 2021 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@legodude17
Copy link

Bug Report

🔎 Search Terms

  • Object is possibly 'null'
  • undefined

🕗 Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about unexpected warnings about possible 'null's and 'undefined's.

I tried versions 3.3.3333 and 4.3.0-beta, though I did not try any in the middle.

⏯ Playground Link

Playground link with relevant code

💻 Code

const refs: {current: {value: number} | null}[] = [{current: { value: 2}}];

if (refs.every((ref) => ref.current != null)) {
    refs[0].current.value = 1;
}

🙁 Actual behavior

"Object is possibly 'null'" warning on refs[0].current

🙂 Expected behavior

No warnings, as they cannot be null since the refs.every(...) is checking that.

@DanielRosenwasser
Copy link
Member

Similar to #16069, maybe #18562.

One of the problems with this is that if something mutates the underlying array, your assumptions would be invalidated.

@andrewbranch
Copy link
Member

I think we can call it a duplicate of / encompassed by #38390

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Apr 5, 2021
@legodude17
Copy link
Author

Yes we can!

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