Skip to content

strictNullChecks produces unnecessary warnings on values which cannot be null #45573

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
willworkforhugs opened this issue Aug 25, 2021 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@willworkforhugs
Copy link

Bug Report

TypeScript reverts to more general type for a variable in an "or" comparison, producing "Object is possibly null" errors for variables which cannot be null at a given point in the code.

🔎 Search Terms

strictNullChecks

🕗 Version & Regression Information

let possibleObj: { someProp: boolean } | null;
possibleObj = { someProp: true };
const goodTest = possibleObj.someProp;
const badTest = true || possibleObj.someProp; // TS error "Object is possibly 'null'" when strictNullChecks === true

@nmain
Copy link

nmain commented Aug 25, 2021

Duplicate of #26914, see also #31855

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Aug 25, 2021
@willworkforhugs
Copy link
Author

I don't understand why this would be intentional behavior. If checking is skipped/degraded on unreachable code for performance reasons, why not show no errors instead of incorrect errors?

@nmain
Copy link

nmain commented Aug 25, 2021

I don't understand why this would be intentional behavior.

It's not; the linked issue is a bug and is still open.

@willworkforhugs
Copy link
Author

It's not; the linked issue is a bug and is still open.

Got it, thanks. Saw lots of closed items there and mistook it as being shelved.

@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