Type annotations can only be used in TypeScript files.ts(8010) - React tsx file

Viewed 395

I am using core-ui project and I am trying implement Typescript on my component files. I'm getting an error from VSCODE which does't allow me to use it in files with tsx extention.

const TheLayout: React.FunctionComponent = () => {}

Getting the following error:

Type annotations can only be used in TypeScript files.ts(8010)

My tsconfig.json file:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "rootDir": "src",
    "outDir": "build",
    "noFallthroughCasesInSwitch": true
  },
  "files.associations": {
    "*.tsx": "typescriptreact",
    "*.ts": "typescriptreact"
  },
  "include": [
    "src"
  ]
}

enter image description here

1 Answers

Sometimes the problem comes when using VSCode type-checkers extensions. In my personal case, I had Flow Type-Checker installed and therefore the linting error jumped up. I turned it off and the error disappeared

Hope it may be useful for you!

Related