babel / babel-eslint

:tokyo_tower: A wrapper for Babel's parser used for ESLint (renamed to @babel/eslint-parser)
https://github.com/babel/babel/tree/main/eslint/babel-eslint-parser
MIT License
2.96k stars 208 forks source link

Typescript as Operator error #761

Closed kayzenkayzen closed 4 years ago

kayzenkayzen commented 5 years ago

I have this code:

const styles = { wrapper: { maxWidth: 1200, display: 'flex', flexDirection: 'column', justifyContent: 'center', margin: '0 auto', background: '#f1f1f1', padding: 35, } as React.CSSProperties }

And I get this eslint error:

`Parsing error: Unexpected token, expected ","

13 | background: '#f1f1f1', 14 | padding: 35,

15 | } as React.CSSProperties | ^ 16 | } 17 | 18 | class App extends React.Component<{}, {}> {`

this is my .eslintrc.json

{ "env": { "browser": true, "es6": true }, "parser": "babel-eslint", "globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly" }, "parserOptions": { "ecmaFeatures": { "jsx": true, }, "ecmaVersion": 2018, "sourceType": "module" }, "plugins": [ "react" ], "overrides": [ { "files": [".test."], "plugins": ["jest"] } ], "rules": { "indent": [2, 4] } }

If I use '@typescript-eslint/parser' I don't get this error, is there something wrong in my configuration?

kayzenkayzen commented 5 years ago

I Fix this using:

wrapper: { } as uknown as React.CSSProperties

r4j4h commented 5 years ago

I am getting this as well, and adding as unknown before does not fix it for me, it just moves the error to the as in the unknown I just added.

nicogreenarry commented 4 years ago

The {} as unknown as <some other type> trick only helps if you've enabled the no-object-literal-type-assertion rule.

kaicataldo commented 4 years ago

Thank you for the issue. Now that @babel/eslint-parser has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.