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
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
Now create ts config file with this command
tsc --init
Maintain folder structure like this
## How to Set Up ESLint and Prettier in a TypeScript Project
FORHAD ・ Jun 28
#webdev
#typescript
#eslint
#prettier
*Update you tsconfig.js file *
{
"compilerOptions": {
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": ["src"]
}
*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',
},
});
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;
Top comments (0)