Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parenthesized non-null assertion in an optional chain #8339

Closed
bradzacher opened this issue May 18, 2020 · 3 comments · Fixed by #8450
Closed

Parenthesized non-null assertion in an optional chain #8339

bradzacher opened this issue May 18, 2020 · 3 comments · Fixed by #8450
Assignees
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

Comments

@bradzacher
Copy link

Prettier 2.0.5
Playground link

# Options (if any):
--parser=typescript

Input:

(x?.y)!.z

Output:

x?.y!.z;

Expected behavior:

(x?.y)!.z

As of TS 3.9, x?.y!.z no longer means (x?.y).z.
Instead, the ! is applied solely to the type of the property y, preserving the optionality of the chain (i.e. x?.y!.z is the same as x?.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.

@sosukesuzuki sosukesuzuki added lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) type:bug Issues identifying ugly output, or a defect in the program labels May 19, 2020
@sosukesuzuki
Copy link
Member

note: we should wait typescript-eslint/typescript-eslint#2036

@sosukesuzuki
Copy link
Member

We also need to wait typescript-eslint/typescript-eslint#2057 to avoid warning.

@bradzacher
Copy link
Author

typescript-eslint/typescript-eslint#2057 will be released on monday morning :)

@sosukesuzuki sosukesuzuki self-assigned this May 28, 2020
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Aug 30, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
Projects
None yet
2 participants