Fixing Typescript/JavaScript error: TS1128: Declaration or statement expected.

index.tsx(11,1): error TS1128: Declaration or statement expected.

If you write a Typescript app, you can get the following error:

For example, the following code triggers this:

namespace app {
  interface IMessage {
    id: string
  }

  class TestApp extends React.Component {
    public render() {
      }
    } 
  } 
}

In this case this is caused by having an extra closing bracket.

An easy way to fix this style of problem is to use a better text editor, like Visual Studio code, and install ESLint, which will warn you if you screw up in this fashion.

One Reply to “Fixing Typescript/JavaScript error: TS1128: Declaration or statement expected.”

Leave a Reply

Your email address will not be published. Required fields are marked *