How can TypeScript rules be incorporated into a Next.js project without compromising next/core-web-vitals?

In my current NextJS project which is in typescript, I have the following configuration in my .eslintrc.json:

{
    "extends": "next/core-web-vitals"
}

Now, I want to include additional typescript rules, such as enforcing the rule of not allowing the use of any type (no-explicit-any).

  1. To start off, I installed the necessary packages using
    npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
  2. I updated the config by adding the no-explicit-any rule, changing the parser, and including the plugin.
{
    "extends": "next/core-web-vitals",
    "parser": "@typescript-eslint/parser",
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
        "@typescript-eslint/no-explicit-any": "warn"
    }
}
  1. Now, the no-explicit-any rule is functioning properly. However, the default rules from next/core-web-vitals are no longer being enforced.

Therefore, I am faced with a dilemma of either sticking with the default next rules or using the typescript-eslint rules. Is there a way to incorporate both sets of rules simultaneously?

Answer №1

To incorporate both presets into an array within a single "extends" property, you can do the following:

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["react", "@typescript-eslint"],
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
    "next/core-web-vitals"
  ],
  "parserOptions": {
    "project": "./tsconfig.json",
  }
}

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

What is the best way to loop through a list of questions and save the answers in an array of user input?

I'm encountering a challenge with iterating through an array of questions to correctly display them on the document. The initial code snippet provided below demonstrates what I aim to accomplish without using prompts. Currently, I have set up an arr ...

How do you trim a string and display the final 3 characters?

When dealing with a list of objects, I want to ensure that the chain of tasks does not become too long and break the table or appear aesthetically unpleasing. Therefore, my goal is to trim the tasks and display only the last 3. In the image below, multiple ...

What is the best choice for UI design framework when creating an ERP web application?

I am in the process of creating a web-based ERP application using Angular Material. However, I've noticed that each input element takes up a significant amount of vertical space on the page. This means if I have 15 input elements, I have to scroll dow ...

Interfacing Highcharts with Angular for seamless data binding across series

I am fairly new to using highcharts and I am having difficulty binding my data into the series parameter. In my controller, I have an array of objects that I want to display (when I use console.log, I can see that they are all properly there) this.plotDa ...

Is there a method to uncover the code that controls the display of a <div> element?

As a fresh face at the company, I've been given the responsibility of developing a chart that is similar to one already present on their website. While I have the knowledge and skills to create it, I am struggling to locate the specific code where the ...

NextJS useEffect does not pause for API response

I'm having trouble fetching the "lovedList" values when the page loads initially. The list gets updated correctly on re-rendering. How can I ensure that it waits for the list values to render the first objects from useEffect? import { Post, PostPro ...

NextJS - Accessing local files with readdir and readFile functions leads to error: Module not found when trying to resolve 'fs' module

I have been working with NextJS and have successfully used the getStaticProps functionality in previous projects to populate data. However, I recently set up a new NextJS project and it seems that this functionality is no longer working. When starting th ...

State is causing a conflict by allowing multiple menus to open when mapping over Menu objects

I am currently encountering an issue with my Material UI <Menu>. The problem arises when I attempt to display some data and interface functionality by mapping over a <Card>, along with adding an <IconButton> on each card that opens a menu ...

await for specialized Redux middleware

Can you explain the process of utilizing await inside a custom middleware function? const handleCustomMiddleware= (store) => (next) => (action) => { if(action.type === 'Start'){ const apiData = await fetchFromApi; } const updat ...

How to Restrict the Use of Conditional "If" Statements in Another Function in Angular 7

How can I use an IF condition inside a function to only execute once for a specific action and not for another action? I have a function that is called twice, but I want the first "IF" condition inside the function to only be triggered when the add bank b ...

How can I ensure that every dependency in my package.json is updated to the newest version using Yarn?

My current react app is using deprecated dependencies and in order to get it functional, I need to update these dependencies to more recent (yet stable) versions. According to a discussion on Stack Overflow, for updating dependencies in package.json to th ...

Tips for utilizing chodorowicz / ts-debounce effectively

Looking to utilize the debounce function provided by the ts-debounce package (available at here) in my typescript project. However, struggling to find a concrete example of its usage in typescript. Would greatly appreciate any help or guidance on this ma ...

Guide to dynamically filtering Google Places API results to specific regions in React

I have been working on a project where I need to dynamically restrict Autocomplete results to a specific country. Currently, I have managed to initialize the API script and obtain results for the default country. However, when a user changes the country, t ...

Transferring information from a React application to a Node Express server

I'm having issues passing data from my React frontend to my Node/Express server using the onSubmit function. The data is not displaying in the console or on the page, and it simply shows up as "undefined." Can someone provide some assistance? App.js ...

Modify a field within MongoDB and seamlessly update the user interface without requiring a page refresh

I am currently working on updating a single property. I have various properties such as product name, price, quantity, supplier, and description. When sending the updated quantities along with all properties to MongoDb, I am able to update both the databas ...

What is the method for striking through a line in a table?

I developed a unique jQuery script: <script type="text/javascript"> $(document).ready(function () { $('tr.inactive').each(function (index) { var tr = $(this); tr.find('td:first').after(function ...

Preventing Redux from triggering re-renders in parent components when using multiple Slate.js editors

I have been facing a challenge as I attempt to integrate multiple Slate.js text editor fields on a single page. Currently, my main component features a button that, when clicked, appends a slate value to an array called slateValues in my redux store. In th ...

Guide to extracting the JSON array from a JSON object with Angular

In my angular application, I have made a call to the API and retrieved a JSON object in the console. However, within this JSON object, there are both strings and arrays. My task now is to extract and parse the array from the object in the console. The JSO ...

Modify MUI's ListItemText component by targeting a specific span to implement customized styles using the useStyle hook

It's quite perplexing that although this is a straightforward task in regular CSS, it must be accomplished through MUI's useStyles for some peculiar reason. Essentially, I possess a ListItem containing a ListItemText. It appears as follows: cons ...

A guide on demonstrating time using the AngularJS date filter

Is it possible to display the time in AM and PM using the angular date filter? I attempted to achieve this with the provided code, however, it did not yield the desired result. <div>{{ '12:31:07' | date:'HH:mm' }}</div> ...