TS2695

error TS2695: Left side of comma operator is unused and has no side effects.

Broken Code ❌

1
2
3
4
5
6
7
8
import express from 'express';

const app = express();

app.use((, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});

Fixed Code ✔️

You just cannot leave out a callback parameter if you don’t want to use it. Mark it with an underscore (_) instead:

1
2
3
4
5
6
7
8
import express from 'express';

const app = express();

app.use((_, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});