Skip to content
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

Object is possibly 'null' when using type guard for for loops #58787

Closed
6 tasks done
fzn0x opened this issue Jun 6, 2024 · 2 comments
Closed
6 tasks done

Object is possibly 'null' when using type guard for for loops #58787

fzn0x opened this issue Jun 6, 2024 · 2 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@fzn0x
Copy link

fzn0x commented Jun 6, 2024

πŸ” Search Terms

if ((uploaded || []).length !== 0) {
  for (let data of uploaded) { // -> this line throws let uploaded: unknown[] | null 'uploaded' is possibly 'null'.ts(18047)
  }
}

βœ… Viability Checklist

⭐ Suggestion

Should not throw

πŸ“ƒ Motivating Example

πŸ’» Use Cases

@fatcerberus
Copy link

This is kind of an odd construction. At any rate TS can't tell that [].length is always 0 (it's just checking the .length of something with an array type, which in general could be anything) so as far as the compiler is concerned uploaded could still be nullish after this check

@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Jun 6, 2024
@fzn0x
Copy link
Author

fzn0x commented Jun 6, 2024

Thanks for tracking this as "Design Limitation". πŸ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

3 participants