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

Bug formatting typescript typecast when in parentheses and using typescript parser #11018

Closed
zxbodya opened this issue Jun 5, 2021 · 5 comments
Labels
lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program

Comments

@zxbodya
Copy link

zxbodya commented Jun 5, 2021

Prettier 2.3.1
Playground link

--parser typescript

Input:

let override = {};
b = (override as any);

Output:

SyntaxError: ',' expected. (2:18)
  1 | let override = {};
> 2 | b = (override as any);
    |                  ^
  3 |

Expected behavior:
Should not have SyntaxError and to remove parentheses when formatting.

@zxbodya
Copy link
Author

zxbodya commented Jun 6, 2021

it looks override variable name is the reason of it - playground link using different name

@sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki added lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program labels Jun 6, 2021
@HolgerJeromin
Copy link
Contributor

HolgerJeromin commented Jun 9, 2022

Is this a duplicate of my code problem?
Both compile in Typescript 4.7.2, but not in 4.6.4 (checked via TS Playground).
But both do throw SyntaxErrors in prettier 2.6.2
I am happy to open a new issue here in this repo if they are really different...
Edit: I just saw that support for TS4.7 is still pending (#12640) so perhaps we have to simply wait for prettier 2.7 release...

Prettier 2.6.2
Playground link

--parser typescript

Input:

export class cls {
     static fn<T = any>(foo: T): T {
        return foo;
    };
}
let foo: Parameters<typeof cls.fn<boolean>> | undefined;

Output:

SyntaxError: '>' expected. (6:34)
  4 |     };
  5 | }
> 6 | let foo: Parameters<typeof cls.fn<boolean>> | undefined;
    |                                  ^
  7 |

But I am confused. My local typescript package was updated to 4.7.2 which compiles this code. I do not know why prettier does not work locally with my code.

@HolgerJeromin
Copy link
Contributor

Both problems are NOT fixed with prettier 2.7.0

@thorn0
Copy link
Member

thorn0 commented Sep 23, 2022

fixed in 2.7.1

@thorn0 thorn0 closed this as completed Sep 23, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
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) scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

4 participants