What causes @typescript-eslint to retain old types/files in its cache and prevent successful compilation?

When I kick off my Typescript application using tsc -b -w, I always encounter an issue with @typescript-eslint not reacting to file changes accurately. It flags invalid types/syntax errors where there are none. Restarting the process sometimes doesn't resolve the problem either. The only workaround is to make some whitespace edits in the file and save it again, hoping that this time it behaves as expected.

For instance:

I recently defined an interface in ./types.ts:

export interface IHaveWorkspace {
  workspace: Workspace;
}

Then, I imported and tried to utilize this interface in index.tsx. But when attempting to access myObj.workspace, I'm greeted with these errors:

[1] src/components/Navigation/index.tsx
[1]   Line 26:29:  Unsafe assignment of an any value                @typescript-eslint/no-unsafe-assignment
[1]   Line 26:29:  Unsafe member access .workspace on an any value  @typescript-eslint/no-unsafe-member-access

Interestingly, it does not flag any issues related to the interface itself. It appears to struggle grasping the interface's types, without raising other errors such as import-related ones. Neither saving the files nor restarting the process seems to work. After introducing some whitespace modifications and subsequent saves, the errors mysteriously vanish.

Configuration Details:

Just for your reference...

.eslintrc.js:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint', 'eslint-plugin-react', 'eslint-plugin-react-hooks'],
  extends: [
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'prettier',
    'prettier/@typescript-eslint',
  ],
  rules: {
    'indent': ['error', 2],
    'linebreak-style': ['error', 'unix'],
    'quotes': ['error', 'single'],
    'semi': ['error', 'always'],
  },
  env: {
    amd: true,
  },
  parserOptions: {
    project: './tsconfig.json',
    tsconfigRootDir: __dirname,
  },
};

And tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "allowJs": true,
    "declaration": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "lib": [
      "es2015",
      "dom"
    ],
    "skipLibCheck": true,
    "rootDir": "src",
    "baseUrl": "src",
    "noFallthroughCasesInSwitch": true
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules"
  ]
}

Answer №1

If you're experiencing this issue in VS Code (based on the comments, it appears to be?), it is a known problem with how the ESLint extension in VS Code handles re-running lint rules when files are changed: https://github.com/microsoft/vscode-eslint/issues/1774. Specifically, the extension does not recompute cross-file information -such as types- after file changes. The quickest way to refresh its understanding is to execute the Restart ESLint Server command in the VS Code editor.

If this issue arises on the command-line (for those encountering this situation), ensure that you are not utilizing ESLint's --cache. ESLint's caching mechanism also does not recognize cross-file dependencies:

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

Error encountered in Azure Pipelines build task: Failure due to requirement for initialization

When I directly invoke index.js using node, everything works fine. However, when running the Mocha tests, the task fails with a "Must initialize" error message. This is how my tasks index.ts code looks like: import * as path from "path"; import tl = requ ...

Setting up NextJs in Visual Studio Code with Yarn

When I used yarn create next-app --typescript to set up a TypeScript Next.js application with Yarn, everything seemed to be working fine with the command yarn run dev. However, Visual Studio Code was not recognizing any of the yarn packages that were added ...

Refactoring TypeScript components in Angular

How can I streamline the TypeScript in this component to avoid repeating code for each coverage line? This angular component utilizes an ngFor in the HTML template, displaying a different "GroupsView" based on the context. <div *ngFor="let benefitG ...

Customizing a side menu by assigning a function to a specific option

Hello there! I am a newcomer to TypeScript and Ionic. I am trying to implement a function that clears the cart when the "Mercado" option in the side menu is clicked, but I am struggling to retrieve the page data. The code snippet below shows my attempt to ...

Types of navigation items based on conditions

I want to create an interface where a navigationItem can have optional childs for a dropdown menu. If the childs property is provided, I want to require the icon property in the navigationItem object. If no childs are given, the icon property should not be ...

Creating a conditional statement within an array.map loop in Next.js

User Interface after Processing After retrieving this dataset const array = [1,2,3,4,5,6,7,8] I need to determine if the index of the array is a multiple of 5. If the loop is on index 0, 5, 10 and so on, it should display this HTML <div class="s ...

Guide to implementing an "export default" with various types and values in a TypeScript module

There is a simple way to export multiple values as default: class Car {...} class Bus {...} export default { Car, Bus } You can also easily export a type as default export default interface Airplane {...} However, exporting multiple types as default i ...

Troubleshooting: Inability to Use Type Assertions while Retrieving Data from

Struggling to retrieve and analyze complex data from Firebase for computation and Cloud Function execution. The format of the data is not aligning with my needs, as shown in this example: interface CourseEvent { coucourseGroupType: string; date: Fireb ...

What is the proper method to deactivate a hyperlink in Angular 2?

I'm currently developing a web application using Angular2, and I find myself in need of displaying, but making it non-clickable, an <a> element within my HTML. Can anyone guide me on the correct approach to achieve this? Update: Please take no ...

Utilize the useState() hook to add an object and display its data in a React Native

Here is a function I am working with: const [dataLoc, setDataLoc] = useState({date: "No data received yet from sensor", coords: {}}); This is where I set the location: Geolocation.getCurrentPosition( location => { const date = d ...

Having difficulty retrieving values while using async-await

Utilizing the code below has been successful for me. I managed to retrieve the data in the spread (then), returning a http200 response. Promise.all([ axios({ method: 'post', url: 'https://oauth2.-arch.mand.com/oauth2/token&a ...

injecting a variable from the configuration service into a TypeScript decorator

I am interested in setting up a scheduled task for my NestJs application to run at regular intervals. I found information on how to use intervals in the NestJs documentation. Since my application uses configuration files, I want to keep the interval value ...

NG6002 error: This error is showing up in the imports of AppModule, even though it has its own set of issues

Running Angular 12 locally is smooth with no errors in the project build. Local Configuration: Angular CLI: 12.0.5 Node: 12.16.3 Package Manager: npm 6.14.4 OS: win32 x64 Angular: 12.0.5 However, when attempting to build the project on a Linux se ...

Tips for displaying a notification about data filtering and loading using the Async Pipe in Angular

Can someone assist me with this issue? I have a code snippet that retrieves characters from an API and allows me to search for specific characters using input. I am trying to display different messages on my HTML page based on the search results. If no it ...

Tips for retrieving an item from a (dropdown) menu in Angular

I am facing an issue with selecting objects from a dropdown list. The array called "devices" stores a list of Bluetooth devices. Here is the HTML code: <select (change)="selectDevice($event.target.data)"> <option>Select ...

Ways to determine if the keys of an object are present in an array, filtered by the array key

Working on an Angular 2 Ionic application and I'm wondering if there's a straightforward way to filter individuals by age in a specific array and then verify if any key in another object matches the name of a person in the array, returning a bool ...

Passing data and events between components in React

I'm currently working on developing a dashboard app that includes a basic AppBar and a drawer. I based my design on this Demo. https://codesandbox.io/s/nj3u0q?file=/demo.tsx In the Demo, the AppBar, Drawer, and Main content are all contained within ...

Create a new WebSocket package for Node.js that allows for segregating connections into

I am currently exploring ways to implement a feature similar to "rooms" using the npm 'ws' package, inspired by how rooms function in socket.io. I want to avoid using socket.io, but I am faced with the challenge of retrieving user/room informatio ...

The table component in Primeng is encountering issues when being used with ngFor

I'm attempting to iterate through an array where each object represents a table in HTML, and it should be displayed like this: <p-table [value]="section" *ngFor="let section of sections"> <ng-template pTemplate="header"> <t ...

Encountering an error when trying to set data in a Firestore document with a customized JavaScript object: "Invalid data provided for function DocumentReference.set()"

For my initial project, I need help in identifying where the issue lies. Firstly, I have a function that adds data to Firebase: addpost() { let newposts = new Posts( this.addForm.value ) this.postsservice.addPosts(newposts); } Ne ...