DEV Community

Cover image for Eslint the danger
md mamun
md mamun

Posted on

1

Eslint the danger

How to crack eslint for a typescript project

*Create a project with this command *

mkdir project-name
cd project-name
npm init -y # for shortcut if you use npm init than you have to modify yourself
Enter fullscreen mode Exit fullscreen mode

Install some indespensible packages

npm install express mongoose cors dotenv --save
npm install typescript @types/node @types/express --save-dev
npm install -D nodemon ts-node-dev eslint @eslint/js @typescript-eslint/parser @typescript-eslint/eslint-plugin prettier
Enter fullscreen mode Exit fullscreen mode

Now create ts config file with this command

tsc --init
Enter fullscreen mode Exit fullscreen mode

Maintain folder structure like this

*Update you tsconfig.js file *

{
  "compilerOptions": {
"module": "commonjs",   
"rootDir": "./src",
"outDir": "./dist",   
"esModuleInterop": true, 
 "forceConsistentCasingInFileNames": true, 
 "strict": true, 
 "skipLibCheck": true                          
  },
  "include": ["src"]
}
Enter fullscreen mode Exit fullscreen mode

*For the last step you have to move eslint.config.mjs file
and paste this *

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config({
    files: ['**/*.ts'],
    extends: [
      eslint.configs.recommended,
      ...tseslint.configs.recommended,
    ],
    rules: {
      '@typescript-eslint/array-type': 'error',
      '@typescript-eslint/consistent-type-imports': 'error',
    },
  });
Enter fullscreen mode Exit fullscreen mode

If you have face import error solve like this

import type { Request, Response } from 'express';
import express from 'express';

const app = express();

app.use(express.json());

app.get('/', (req: Request, res: Response) => {
  res.send('Hello from setup file');
});

export default app;
Enter fullscreen mode Exit fullscreen mode

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more