Default linter and/or linting configuration cannot parse various TypeScript features (e.g. modifiers like readonly)
See original GitHub issueIs this a bug report?
Yes
Did you try recovering your dependencies?
The issue occurs on a freshly created application.
Which terms did you search for in User Guide?
Linting, Readonly, TypeScript
Environment
Environment Info:
System:
OS: macOS Sierra 10.12.6
CPU: x64 Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz
Binaries:
Node: 10.15.1 - ~/.nodenv/versions/10.15.1/bin/node
npm: 6.7.0 - ~/.nodenv/versions/10.15.1/bin/npm
Browsers:
Chrome: 72.0.3626.96
Firefox: 64.0.2
Safari: 12.0.3
npmPackages:
react: ^16.8.1 => 16.8.1
react-dom: ^16.8.1 => 16.8.1
react-scripts: 2.1.5 => 2.1.5
npmGlobalPackages:
create-react-app: 2.1.5
Steps to Reproduce
-
Generate an app with the typescript option:
create-react-app my-app --typescript
-
Add TypeScript code with the
readonly
modifier, for example insrc/App.tsx
:interface Test { readonly foo: string }
-
Observe that eslint cannot parse the code, as indicated by the editor if integrated with eslint, or by running the following command:
$> ./node_modules/eslint/bin/eslint.js src/App.tsx /path/to/my-app/src/App.tsx 6:12 error Parsing error: Unexpected token, expected ":" 4 | 5 | interface Test { > 6 | readonly foo: string; | ^ 7 | } 8 | 9 | class App extends Component { ✖ 1 problem (1 error, 0 warnings)
Expected Behavior
The linter with its default configuration should be able to parse this interface.
Actual Behavior
The linter fails to parse the interface with the error:
error Parsing error: Unexpected token, expected ":"
Removing the readonly modified removes the parsing error.
Reproducible Demo
This repository demonstrates the issue with a simple commit.
Run the following command to reproduce:
git clone https://github.com/AlphaHydrae/create-react-app-typescript-readonly-bug.git && \
cd create-react-app-typescript-readonly-bug && \
npm ci && \
./node_modules/eslint/bin/eslint.js src/App.tsx
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
readonly modifier doesn't propagate when extending classes ...
Here is the code on TypeScript's playground. I think I'm gonna switch my approach into the Readonly<T> generic because it seems to be...
Read more >JavaScript Type Linting - Medium
This simple technique uses Visual Studio Code and its TypeScript language server runing in the background. As you type your JavaScript, ...
Read more >TypeScript Data Modifiers: public, private, protected, static ...
There are three types of access modifiers in TypeScript: public, private and protected. ... By default, all members of a class in TypeScript...
Read more >Accelerator - Electron - W3cubDocs
Accelerators are Strings that can contain multiple modifiers and a single key code, ... It includes an example typescript configuration and provides two ......
Read more >adams allen allison alvarez anderson andrews armstrong
... chapara chaplino chapogir chapuli chapultenango chara characteristics characterized characters charani charazani charberd charchan charco chari chariar ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there any update on this, I’m seeing the same issue using react-scripts 4.0.1
Wow. That is weird. I was able to resolve the issues by defining my own eslint config with typescript parser and plugin.