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

False positive for error: TS2873: This kind of expression is always falsy. #59505

Closed
dasa opened this issue Aug 1, 2024 · 0 comments · Fixed by #59507
Closed

False positive for error: TS2873: This kind of expression is always falsy. #59505

dasa opened this issue Aug 1, 2024 · 0 comments · Fixed by #59507
Assignees
Labels
Bug A bug in TypeScript

Kommentare

@dasa
Copy link

dasa commented Aug 1, 2024

🔎 Search Terms

"TS2873"

🕗 Version & Regression Information

Tested in 5.6.0-beta and 5.6.0-dev.20240801

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240801#code/DYUwLgBAbghsCuIBcEYDsCeEC8E32GAG4AoEgYwHs0BnS0AOmEoHMAKN2BECAH14jw0AExAAzAJZoQwgJQQAZAogBGCAHpocRLKIbNAWgB8gkeKkyK1Oo2bsuiRcrWaHIXfojG8BYCSA

💻 Code

let value: any = null;

console.log((value || undefined) && 1 / value); // -> undefined
console.log(value && 1 / value); // -> null

🙁 Actual behavior

"TS2873: This kind of expression is always falsy." is reported for undefined in the first log call.

🙂 Expected behavior

No error since undefined is affecting the behavior. Without undefined the expression evaluates to null.

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh self-assigned this Aug 1, 2024
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 1, 2024
RyanCavanaugh added a commit to RyanCavanaugh/TypeScript that referenced this issue Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants