How can I disable Typescript errors in VSCode for .JS / .JSX files while still keeping them for .TS / .TSX files?

Utilizing both typescript and plain javascript can be tricky. Some files are in JavaScript (.js) format, while others are in TypeScript (.ts) format.

Despite this setup, I am encountering Typescript Errors & Warnings with my eslint in VSCode, even when working on plain JavaScript files.

Is there a way to disable these errors for the .js files specifically, but keep them enabled for any file with a .ts / .tsx extension?

The eslint and typescript configurations I am currently using are based on Vercel's official typescript example.

.eslintignore :

**/node_modules/*
**/out/*
**/.next/*

.eslintrc.json :

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    // Uncomment the following lines to enable eslint-config-prettier
    // Is not enabled right now to avoid issues with the Next.js repo
    "prettier",
    "prettier/@typescript-eslint"
  ],
  "env": {
    "es6": true,
    "browser": true,
    "jest": true,
    "node": true
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  },
  "rules": {
    "react/react-in-jsx-scope": 0,
    "react/display-name": 0,
    "react/prop-types": 0,
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/explicit-member-accessibility": 0,
    "@typescript-eslint/indent": 0,
    "@typescript-eslint/member-delimiter-style": 0,
    "@typescript-eslint/no-explicit-any": 0,
    "@typescript-eslint/no-var-requires": 0,
    "@typescript-eslint/no-use-before-define": 0,
    "@typescript-eslint/no-unused-vars": [
      2,
      {
        "argsIgnorePattern": "^_"
      }
    ],
    "no-console": [
      2,
      {
        "allow": ["warn", "error"]
      }
    ]
  }
}

tsconfig.json :

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "exclude": ["node_modules", ".next", "out", "**/*.js", "**/*.jsx"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"] 
}

https://i.sstatic.net/hmgwi.png

Answer №1

To exclude all JavaScript files from ESLint, simply add this line to your .eslintignore file:

**/*.js

With this addition, ESLint will ignore any files with a .js extension during linting.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to verifying the type of response from an HTTP request in Typescript

Issue: I am currently working with Firebase cloud functions and encountering a specific problem. Let's consider the following function: function giveMeAnInteger(): number { return 123; } When calling this function like so: function call() { ...

Restrict allowable dates according to user preference

In my Leave request form, employees can request various types of leaves such as paid leave, unpaid leave, and leave for blood donation. These types are stored in a Mysql table and displayed in a dropdown using the following code: <div class="form-g ...

Vetur is experiencing issues with template functionality, such as not properly checking data and methods

I have incorporated the vetur extension into my Visual Studio Code for a Vue project using TypeScript. I recently discovered that vetur has the capability to perform type checks within the template tag for props, methods, and even variables. However, in ...

Encountering Error with Axios in Nuxt while Navigating Pages

Working on a nuxt application utilizing axios for API calls. In my index.vue file, I have the code snippet below. <template> <div> <Hero /> <Homebooks :details="details" /> </div> </template> <s ...

Tips for showing/hiding textboxes based on select options:

I am currently working on a project that allows users to enter their personal information. I need help figuring out how to show or hide textboxes based on the selection made in a dropdown menu. The dropdown menu in question is for marital status. The opt ...

How to pass parameters from a directive to a child component in Angular

I am currently attempting to create a child component that can pass parameters using a directive, but I have not been able to find any tutorials on how to achieve this yet. I have tried looking at some resources, such as this one on Stack Overflow: Get re ...

Can Javascript be used to open a new window, send POST parameters to it, and pass the request as application/json?

I have a browser client application built with JavaScript that manages a large amount of state data. Sometimes, this data needs to be organized into a structured object and sent to a new window for further processing. Currently, I am using a solution wher ...

What are some effective methods for troubleshooting npm modules?

Typically, the process involves installing React with yarn/npm install react and then using it by importing React from 'react' Imagine you need to debug a React source code, so you clone a GitHub repository. But how do you incorporate this sour ...

How can I access a file uploaded using dxFileUploader?

I am facing an issue with retrieving a file from dxFileUploader (DevExpress) and not being able to read it in the code behind. The file is only appearing as an object. Here is My FileUploader : { location: "before", ...

Is the reference to a variable within an array maintained by JavaScript?

I'm working with react code and using the find() method to select an item from an array. When I retrieve an item from the array, is JavaScript copying the item or returning a reference? EDIT: The items in my array are objects, such as [{id: 12, name ...

A beginner's guide to crafting a knex query with MySQL language

Within MySQL Workbench, I currently have the following code: USE my_db; SELECT transactions.created_at, price FROM transactions JOIN transactions_items ON transactions.id = transactions_items.transaction_id JOIN store_items ...

Encountering CORS Problem when Logging in to LastFM API

I have been experimenting with the lastFM API. To begin, I created a simple template focused on connecting to the LastFM API and authenticating myself. In my HTML page, there is a button- <button id="auth">AUTHENTICATE</button> Below is the j ...

Issue with "Maximum call stack.." error triggered by RequireJS version 2.1.9 in combination with Grunt

I've encountered an issue while using Grunt to construct a multi-module application (Backbone, Marionette, RequireJS, Handlebars). The error message "Error: RangeError: Maximum call stack size exceeded" keeps appearing. Interestingly, replacing the r. ...

Adjust the burger menu color based on the background color of the section

Currently, I am working on creating a hamburger menu component with fixed positioning using the 'fixed' property. The menu icon consists of three white lines by default, but I want them to change to black when placed in a white section. I have tr ...

TextGeometry in Three JS is designed to always face the user

Here is the source code I have been working on. My main goal is to make sure that TextGeometry is always facing the camera. Is this possible? Code: var stats; var camera, controls, scene, renderer; init(); render(); functi ...

A class or another interface is the only type that an interface is allowed to extend

We are currently using typescript version 2.9.2 I encountered an issue while trying to extend the interface DropDownOption. I received the error "error TS2312: An interface may only extend a class or another interface." Is there an alternate approach to ...

Utilizing JavaScript and the Document Object Model (DOM) to display images within a

My main goal is to have images load dynamically as the background of the browser frame, without any white spaces or repeats. I've successfully achieved this statically, but now I want to implement it so that different images are generated randomly. W ...

Tips for updating the name of a variable (such as 'data') following the process of destructuring, like with the

If I have 2 SWR hooks in the same function (or some other hook that contains a data variable), export default function Panel() { const { data, error } = useSWR("/api/customer", fetcher); const { data, error } = useSWR("/api/user", fetch ...

What is the best way to save multiple data entries within a single field in Firestore?

I'm in the process of developing a like button with a counter feature for my app. Each card within the app is assigned a unique sale_id number, which is passed into my component. In Firestore, I am saving this sale_id: const addLikeDocument = async ( ...

Switching from AngularJS to vanilla JavaScript or integrating AngularJS and Flask on a single server

It is common knowledge that angular has the ability to create a project and convert it into pure HTML, CSS, and js code. Similarly, I am looking to do the same for my AngularJS application. When I execute the app using npm start it works perfectly fine. My ...