Parenthesized non-null assertion in an optional chain #8339
Labels
lang:typescript
Issues affecting TypeScript-specific constructs (not general JS issues)
locked-due-to-inactivity
Please open a new issue and fill out the template instead of commenting.
type:bug
Issues identifying ugly output, or a defect in the program
Prettier 2.0.5
Playground link
# Options (if any): --parser=typescript
Input:
Output:
Expected behavior:
As of TS 3.9,
x?.y!.z
no longer means(x?.y).z
.Instead, the
!
is applied solely to the type of the propertyy
, preserving the optionality of the chain (i.e.x?.y!.z
is the same asx?.y.z
, and(x?.y)!.z
is the same as(x?.y).z
).This means that now automatically removing the parentheses in this case is wrong, and changes the meaning of the code.
The text was updated successfully, but these errors were encountered: