Error: 'types' can only be used in a .ts file

December 21, 2022

Error: ‘types’ can only be used in a .ts file

Error: 'types' can only be used in a .ts file

Solution 1

For anyone who lands here and all the other solutions did not work give this a try. I am using typescript + react and my problem was that I was associating the files in vscode as.

javascriptreact not typescriptreact so check your settings for the following entries.

"files.associations": {
    "*.tsx": "typescriptreact",
    "*.ts": "typescriptreact"
  },

Solution 2

Use "javascript.validate.enable": false in your VS Code settings, It doesn’t disable ESLINT.

Adding this line in settings.json. Helps `“javascript.validate.enable”: false`


Written by Manoj Bhardwaj who lives and works in Dharamshala Himachal Pradesh (India). My stackoverflow