ESLint is unable to recognize the types of redux and redux-thunk

Recently, I started incorporating ESLint rules into the project that utilizes TypeScript. However, I encountered an issue with Redux and Redux-Thunk types. Whenever I attempt to import any type from Redux or Redux-Thunk, ESLint flags an error:

import { Action, AnyAction, applyMiddleware, combineReducers, createStore } from 'redux';
import thunkMiddleware, { ThunkAction, ThunkDispatch } from 'redux-thunk';

The ESLint error message reads as follows:

>> Action not found in 'redux'
>> AnyAction not found in 'redux'
>> ThunkAction not found in 'redux-thunk'
>> ThunkDispatch not found in 'redux-thunk'

In an effort to resolve this issue, my initial instinct was to install types for Redux and Thunk. Strangely enough, both packages indicated that Redux now comes bundled with its types automatically, negating the need for a separate installation.

It's worth noting that despite the ESLint errors, the application functions smoothly and all necessary types are present.

To work around the issue, I made the following adjustment in the .eslintrc file:

settings: {
    'import/core-modules': ['redux', 'redux-thunk']
}

Question: Having implemented this workaround, I am curious about the proper way to set up the ESLint configuration without resorting to such solutions?

UPD

This is my eslintrc file content:

{
  "root": true,
  // Other configuration options...
}

Upon including the settings section to reference the tsconfig file:

  "settings": {
    "import/resolver": {
      "typescript": {
        "project": "tsconfig.json"
      }
    }
  }

A new ESLint error surfaces:

Resolve error: typescript with invalid interface loaded as resolver

Answer №1

The error cannot be replicated:

.eslintrc

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended"
  ]
}

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "redux": "^4.1.2",
    "redux-thunk": "^2.4.1",
    "typescript": "^4.5.4"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.9.1",
    "@typescript-eslint/parser": "^5.9.1",
    "eslint": "^8.7.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "lint": "eslint . --ext .ts"
  },
  "author": "",
  "license": "ISC"
}

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

There are no properties associated with this particular data type

As someone who is new to TypeScript, I am encountering two issues with data types. This snippet shows my code: const say: object = { name: "say", aliases: [""], description: "", usage: "", run: (client: ob ...

Utilizing Angular Material Table with a distinct header row for every table row

Looking for help with creating an Angular Material table that includes a header for every other row. Here is a basic sketch to illustrate: https://i.sstatic.net/kpptk.png Using separate tables seems like the best approach, but it may lead to a messy layo ...

Angular interceptor allows the execution of code after the outgoing request has completed its process

In the process of creating a simple interceptor, I have encountered an issue. The interceptor is designed to check if an outgoing request is targeting a specific endpoint type, namely events and favoriteevents. While the interceptor works almost as intend ...

Transformation occurs once you subscribe to an observable entity

Within the x.component.ts, I initiate the getSomething() method from y.service.ts. Since this method returns an observable, I subscribe to it. However, I encounter a peculiar issue where an object with 4 elements, one being an array of number arrays (numbe ...

Declaration in Typescript for an array of strings that will be returned as a

I am facing an issue with my async function that is supposed to return either a single string or an array of strings. Here is the relevant code snippet: async getAllAnnotationTimes(): Promise<string> | Promise<string[]> { return aw ...

Following an update, the functioning of Visual Studio Tools for Apache Cordova ceases to operate accurately

Currently working on an ionic application using Visual Studio Tools for Apache Cordova, everything was going smoothly until I decided to update the Tools for Apache Cordova and TypeScript Tools for Visual Studio. Following the update, the Ripple emulator s ...

Troubleshooting a Deployment Problem in Azure timerTrigger Function with Service Bus Integration

I've been developing an Azure Function that utilizes a timer trigger and interacts with Azure Service Bus. Initially, the function deploys successfully when it only contains the timer trigger code. import { app, InvocationContext, Timer } from "@ ...

Developing a secure private class member access function in TypeScript

One interesting feature of TypeScript is its ability to access instance properties and methods that have been declared as `private instanceProperty`, but not explicitly as `#instanceProperty`. Despite this, TypeScript still performs type checking on this ...

How exactly does the 'this' type in TypeScript determine its own type inferences?

When working with TypeScript, I wanted to use the this keyword to type certain properties of my class. However, I encountered a problem that I couldn't figure out how to solve. What I was trying to achieve is something like this: export class Animal{ ...

What is the best way to enable code sharing between two TypeScript projects housed within the same repository?

Our project has the following structure: api (dir) -- package.json -- tsconfig.json -- src (dir) -- client (dir) ---- package.json ---- tsconfig.json ---- src (dir) The "client" directory houses a create-react-app project that proxies to the API d ...

What is the best way to organize the snapshots folder in a React project?

Currently, I am working on a React UI project that I must build by myself. Given the small size of the project, I have decided to use TypeScript and adopt a Test-Driven Development (TDD) approach. During this process, I've familiarized myself with be ...

The Object filter is experiencing a delay with processing 10,000 items

When an API returns over 10,000 objects in the format of {firstName:'john',lastName:'Cena'}, I am faced with a performance issue. In my parent React component, I make the API call in componentDidMount and pass this object to child compo ...

Is it feasible in Angular 10 to have varying data for dynamic routes?

Take a look at the following dynamic route: export const routes: Routes = [ { path: 'template/:templateId', component: TemplateComponent, data: { pageTitle: 'TEMPLATES'} }] Can we dynamically change the pageTitle for the ...

Function arity-based type guard

Consider a scenario where there is a function with multiple optional parameters. Why does the function's arity not have a type guard based on the arguments keyword and what are some solutions that do not require altering the implementation or resorti ...

Integrating JavaScript functions into TypeScript

When converting a JavaScript function to TypeScript, I encountered an issue. The function works fine in JS but in TS, I receive the following error: [ts] Cannot find name 'PasscodeAuth'. Did you mean 'passcodeAuth'? function passco ...

Utilizing Database values in .css files with Vue.js and TypeScript

I am currently working on extracting a color value from the database and applying it to my external .css files. I have searched extensively online but haven't found a satisfactory solution yet. Here is the JavaScript code snippet: createBackgroundHead ...

Warning: Trying to access an undefined property within an async function in Typescript

Recently, I have been tackling an issue with my API that is built with TypeScript and NodeJS. The problem arises when my Promises seem to not resolve correctly in the following code snippet: async function retrieveData() { return new Promise((reso ...

Saga Redux fails to pass parameters during post requests

This is my first time using redux Saga to handle API requests. I have created an async function for a simple post request in the following way: const onLoginRequest = async (userName, password) => await fetch(`${loginApi}`, { method: 'POST', ...

Angular 6 - The state of the expression was altered after it was verified, different types of constructions

During the build process in debug mode with ng build, I am encountering errors in some components. However, when I switch to production mode using ng build --prod, these errors disappear. I am curious as to why this discrepancy is occurring. Error: Expre ...

Tips on adding an item to an array with React hooks and TypeScript

I'm a beginner with a simple question, so please bear with me. I'm trying to understand how to add an Object to the state array when a form is submitted. Thank you for your help! interface newList { name: string; } const ListAdder = () => { ...