What are the benefits of combining 'eslint' and 'typescript-eslint' for TypeScript linting as opposed to just using 'tsc'?

Objective: Developing a rigorous TypeScript linter script

eslint scans for problematic JavaScript code patterns. The documentation recommends initiating eslint with npm init @eslint/config@latest

This process also installs typescript-eslint

But what is the purpose of using typescript-eslint?

As per the information on the official website, it:

enables esLint to analyze TypeScript code

However, upon removing typescript-eslint, esLint seems to function properly.

Further examination reveals that typescript-eslint fails to identify an undefined error, which is caught by tsc:

// Type "pink" is undefined
const apple: pink = 'apple'
console.log(apple)

My understanding is that tsc converts TypeScript into JavaScript unless specified with the --noEmit flag. By utilizing configurations like "strict": true, TypeScript rules can be set up for validation.

Is typescript-eslint essentially irrelevant for linting purposes?

It appears that typescript-eslint may not serve its intended function and might need to be eliminated. Meanwhile, tsc proves effective in detecting errors.

Answer №1

It seems that removing typescript-eslint allows esLint to function properly.

When you mention it functioning normally, are you referring to its performance in your IDE (such as vscode) or when executing the eslint command? Most IDEs come with eslint integrated or offer it as a package for in-editor linting (utilizing a typescript parser behind the scenes). Without typescript-eslint, eslint is unable to parse your typescript files. Try running eslint without it to see if it works.

My understanding is that tsc compiles TypeScript to JavaScript unless the --noEmit flag is included. By setting options like "strict": true, TypeScript rules can be configured for checking.

ESLint and tsc serve different purposes.

  • Executing tsc detects type errors, which eslint does not do.
  • Running eslint identifies linting errors (breaches of defined rules) rather than type errors, something that tsc does not handle.

ESLint only flags errors from its own linters and does not signal typescript compilation issues. Read more at:

The purpose of the typescript-eslint tool is explained thoroughly here:

ESLint and TypeScript interpret code differently internally. ESLint's default JavaScript parser cannot inherently interpret TypeScript-specific syntax, and its rules lack direct access to TypeScript's type information.

Answer №2

tsc is responsible for compiling the project and identifying any build errors, like in the example you provided. ESLint, on the other hand, is utilized to detect patterns that may not be ideal. It's important to note that ESLint should be run on your code rather than on the code generated by the Typescript compiler. This is where typescript-eslint comes into play, especially when working with Typescript, as it allows ESLint to understand Typescript better, as mentioned on their homepage:

The tools that enhance ESLint and Prettier to support TypeScript.

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

TypeScript - creating a dynamic instance of a new class with a custom

Looking to dynamically create new class objects in a loop with customizable names? For example, having classes like "tree": export default class ParentClass { // ... } export default class Thomas extends ParentClass { // ... } export default cla ...

Looking to personalize the MUI - datatable's toolbar and place the pagination at the top?

I successfully managed to hide the toolbar icon, but I am struggling with positioning pagination from bottom to top. Additionally, I am attempting to add two buttons (reset and apply) in the view-Column toolbar without any success in customizing the class. ...

Angular application code modifications do not reflect in the browser

After making changes to the HTML file of an Angular component, the browser does not reflect those changes when connected to localhost. Even though the old string is no longer present in the project, the browser continues to display it. Interestingly, openi ...

Issue encountered while running the 'yarn install' command in a React project: 'The system does not recognize the term 'yarn'

When attempting to run the 'yarn install' command in my React project, I'm running into a problem. Even though I have Yarn installed globally (npm install --global yarn), I keep getting an error when trying to use any Yarn command in the ter ...

Convert an enum value to a String representation

I need assistance with converting my enum value to a string format export enum Roles { manager = "manager", user = "user" } console.log(" Roles.manager: ", Roles[Roles.manager]); The following is displayed in the console: Roles.manager: manage ...

Locate a class using an interface

Consider the code snippet below: interface FirstInterface {} interface SecondInterface {} interface ThirdInterface {} class TheClass { constructor(howdy: FirstInterface) {} } class Foo implements FirstInterface {} class Bar implements SecondInterface ...

Setting up @cypress/code-coverage with Angular and TypeScript: A comprehensive guide

When following the instructions in Cypress documentation for @cypress/code-coverage, it recommends using the following code... // cypress/support/e2e.js import '@cypress/code-coverage/support' ...as well as... // cypress.config.ts import { defin ...

JavaScript's blank identifier

One interesting feature in Golang is the use of the _ (Blank Identifier). myValue, _, _ := myFunction() This allows you to ignore the 2nd and 3rd return values of a function. Can this same concept be applied in JavaScript? function myFunction() { re ...

Opt for ion-select with a range of i to j options

Looking to set up an ion-select menu in Ionic4 where users can pick a value between 20 and 220 without manually typing each number. I attempted to use the approach detailed in this post Tersest way to create an array of integers from 1..20 in JavaScript ...

Mastering the Type Model on Firestore Function to Retrieve Field ValuesUnlock the potential of the Type

When retrieving data from Firestore, I am able to print the entire object using doc.data. However, I am having trouble accessing the specific value of unixtime as it is coming through as undefined. I need help in correctly applying my type model so that I ...

Can you change the method definition of a built-in class using TypeScript?

Working with the Web Audio Api in TypeScript has presented me with a minor issue. I am trying to enhance AudioParam's prototype by adding some convenience methods that can be used on any parameter. However, I keep getting an error from the compiler st ...

A guide to leveraging React.lazy within your Gatsby projects

When attempting to use React.lazy in Gatsby for production by running gatsby build, errors may arise. What would be the most effective approach to implement React.lazy and suspense in a Gatsby Project? ...

Testing React Hooks in TypeScript with Jest and @testing-library/react-hooks

I have a unique custom hook designed to manage the toggling of a product id using a boolean value and toggle function as returns. As I attempt to write a unit test for it following a non-typescripted example, I encountered type-mismatch errors that I' ...

Namespace remains ambiguous following compilation

I'm currently developing a game engine in TypeScript, but I encountered an issue when compiling it to JavaScript. Surprisingly, the compilation process itself did not throw any errors. The problem arises in my main entry file (main.ts) with these ini ...

Using Node with Express and TypeScript to serialize date types as epoch milliseconds universally

I am looking to update my node-based API backend to serialize all Date types as Epoch milliseconds instead of ISO format. For instance, if I have the following interface: export interface Profile { updatedAt: Date; updatedBy: string; } And when I ...

Is there a way to prevent this React function from continually re-rendering?

I recently created a small project on Codesandbox using React. The project involves a spaceship that should move around the screen based on arrow key inputs. I have implemented a function that detects key presses, specifically arrow keys, and updates the ...

Angular 6 Material now allows for the selection of a mat-tab-link by displaying an underlining bar

My website features a mat-tab-nav-bar navigation bar, but I'm facing an issue with the mat-tab-link blue underlining bar. It doesn't move to highlight the active button, instead, it stays on the first button. However, the buttons do change into t ...

Issues arise when upgrading from Angular 8 to 9, which can be attributed to IVY

After successfully upgrading my Angular 8 application to Angular 9, I encountered an error upon running the application. { "extends": "./tsconfig.json", "compilerOptions": { "outDir": ". ...

How to set up npm to utilize the maven directory format and deploy war files

Embarking on my very first pure front-end project, I decided to deploy it using Java/Maven. To begin, I set up a standard WAR project: │ package.json │ pom.xml │ tsconfig.json │ typings.json │ │ ├───src │ └───main ...

Discover the contents of an Object's key in TypeScript

I currently have a variable of type object. let ref_schema_data: object The value of ref_schema_data: { '$schema': 'http://json-schema.org/draft-07/schema', '$id': 'tc_io_schema_top.json', allOf: [ { type: &a ...