question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default linter and/or linting configuration cannot parse various TypeScript features (e.g. modifiers like readonly)

See original GitHub issue

Is 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

  1. Generate an app with the typescript option:

    create-react-app my-app --typescript
    
  2. Add TypeScript code with the readonly modifier, for example in src/App.tsx:

    interface Test {
      readonly foo: string
    }
    
  3. 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:open
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
foffercommented, Jan 1, 2021

Is there any update on this, I’m seeing the same issue using react-scripts 4.0.1

Screenshot 2021-01-01 at 08 47 38
0reactions
JustinTRosscommented, Apr 1, 2019

Wow. That is weird. I was able to resolve the issues by defining my own eslint config with typescript parser and plugin.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found