"Never nullish" checks miss "never nullish" through parens
🔎 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
🤖 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
- (70%) microsoft/typescript#44988: Parentheses in nullish coalescing chains impacts type narrowing
- (66%) microsoft/typescript#62119: TS2869 not fired on `stubTrue() ?? false`
- (66%) microsoft/typescript#31855: Prepending `true ||` confuses strict null checks, even with correct bracketing
- (65%) microsoft/typescript#59546: "This binary expression is never nullish" errors due to the way I format my code
If your issue is a duplicate of one of these, feel free to close this issue. Otherwise, no action is needed.