You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nullish coalescing chain parentheses type narrowing prettier
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about nullish coalescing. Note that at the time of writing, 4.3.5 was the latest stable release.
getResult1 throws a type error, as TypeScript incorrectly infers that value2.b has a type of string | undefined.
getResult2 does not throw a type error, as TypeScript correctly infers that value2.b has a type of string.
🙂 Expected behavior
The existence and placement of parentheses in nullish coalescing chains should not impact type narrowing, as to my knowledge (and prettier, as it automatically removes the parentheses seen in getResult2), x ?? y ?? z and x ?? (y ?? z) actually behave the same at runtime.
The text was updated successfully, but these errors were encountered:
joealden
changed the title
Parentheses in Nullish Coalescing Chains Impact Type Narrowing
Parentheses in nullish coalescing chains impact type narrowing
Jul 12, 2021
joealden
changed the title
Parentheses in nullish coalescing chains impact type narrowing
Parentheses in nullish coalescing chains impacts type narrowing
Jul 12, 2021
Bug Report
🔎 Search Terms
nullish coalescing chain parentheses type narrowing prettier
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about nullish coalescing. Note that at the time of writing, 4.3.5 was the latest stable release.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
getResult1
throws a type error, as TypeScript incorrectly infers thatvalue2.b
has a type ofstring | undefined
.getResult2
does not throw a type error, as TypeScript correctly infers thatvalue2.b
has a type ofstring
.🙂 Expected behavior
The existence and placement of parentheses in nullish coalescing chains should not impact type narrowing, as to my knowledge (and
prettier
, as it automatically removes the parentheses seen ingetResult2
),x ?? y ?? z
andx ?? (y ?? z)
actually behave the same at runtime.The text was updated successfully, but these errors were encountered: