Closed
Description
🔎 Search Terms
Ever since Typescript 5.6, we've been getting false positives of the nullish operand lint rule. Our codebase is littered with it so it blocks us from upgrading to the latest Typescript
🕗 Version & Regression Information
- This changed between versions 5.5 and 5.6 (also there on latest 5.7.2)
⏯ Playground Link
💻 Code
function x<T>(strings: TemplateStringsArray, ...values: number[]): T | null {
return null as never
// ^ you can also remove the above line, unrelated to the bug, only there to suppress
// an unrelated error.
}
// Does not work: Left side is never nullish
const value: number = x<number>`hi` ?? 0
// ^ this line causes an error in Typescript
// Works?
const value2 = x<number>`hi`
const value3: number = value2 ?? 0
🙁 Actual behavior
Right operand of ?? is unreachable because the left operand is never nullish
🙂 Expected behavior
No error
Additional information about the issue
I tried looking for duplicate issues but wasn't able to find any. If the bug has already been filed, a link to it would be appreciated. Thanks!