-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[no-extra-parens] incorrect behaviour with angle bracket assertions #742
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
Comments
It seems like this #12 . |
in a way, it's the same bug. |
There's a reason that angle bracket assertions conflict with JSX syntax, which is very widely used. It causes people confusion in codebases that don't use JSX because it looks the same as it. angle bracket assertions also causes confusion with generics, because they use the same tokens to delimit the start/end. declare const x: <T>() => T;
const foo = <number>x<string>();
const bar = <() => void>(<T>(arg: T) => {}); Where as the same examples using as assertions is clear, and does not suffer from the same confusion as complexity grows. declare const x: <T>() => T;
const foo = x<string>() as number;
const bar = (<T>(arg: T) => {}) as () => void; |
@bradzacher thanks for your reply. |
@bradzacher Hi, I'm not sure if this should be fixed in parser level? bradzacher/eslint-plugin-typescript#130 (comment) If I just put this code and run debugger, I get let cookies = (<Headers> requestInit.headers).get('Cookie') |
It's not a parser error. You just have to make sure you don't turn on JSX mode if you're going to be using angle bracket parsing (i.e. don't name files as |
Repro
Expected Result
No error
Actual Result
Got error
Unnecessary parentheses around expression.eslint(@typescript-eslint/no-extra-parens)
and be changed to below if run
eslint --fix
Additional Info
Versions
@typescript-eslint/eslint-plugin
1.13.0
@typescript-eslint/parser
1.13.0
TypeScript
3.5.3
ESLint
6.1.0
node
10.16.0
npm
6.9.0
The text was updated successfully, but these errors were encountered: