TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

"Never nullish" checks miss "never nullish" through parens

Open jakebailey opened this issue 1 month ago • 1 comments

🔎 Search Terms

never nullish parenthesis

🕗 Version & Regression Information

  • This changed between versions 5.8 and 5.9

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAHgLhgbxgTydATgSzAcxgB8YBXMAEwFMAzPKimAX2LMtvsYF43q6wGMAIYRhYNAG4AsAChZs0JFg0QIGDzgB+AHRoYmzTAAGqgA4Qj+wwCJr0mYugwARkKzqYACi26rxsxYAlH629grgECAANlTaUSD4nioggfaO0bHxia5YqUA

💻 Code

const x: { y: string | undefined } | undefined = undefined as any;


const foo = x?.y ?? `oops` ?? "";
const bar = (x?.y ?? `oops`) ?? "";

console.log(foo);
console.log(bar);

🙁 Actual behavior

Error on foo's expression, no error on bar's.

🙂 Expected behavior

Error on both; both expressions are guaranteed to be "oops".

Additional information about the issue

No response

jakebailey avatar Nov 20 '25 20:11 jakebailey

🤖 Thank you for your issue! I've done some analysis to help get you started. This response is automatically generated; feel free to 👍 or 👎 this comment according to its usefulness.

Similar Issues

Here are the most similar issues I found

If your issue is a duplicate of one of these, feel free to close this issue. Otherwise, no action is needed.

RyanCavanaugh avatar Dec 01 '25 18:12 RyanCavanaugh