Eric Liprandi Eric Liprandi - 1 year ago 253
TypeScript Question

how can I avoid TS6133 errors when using anonymous methods?

We have a TypeScript project that I am trying to clean-up a bit.
I started turning on stricter type-checking. Today, I just enabled

noUnusedParameters
in
tsconfig.json
.

We use
expressJS
and the following code is getting flagged with a
error TS6133: 'req' is declared but never used.


How can I rewrite this to comply?

import * as express from 'express';

const app = express();

app.get('/', (req, res) => {
res.sendStatus(200);
});


Obviously, I have to declare
req
if I want to have
res
.

Answer Source

You can resolve this error by prefixing or replacing the unused parameters with an underscore. In this case, you could prefix req as _req:

app.get('/', (_req, res) => {
  ...
});

See this post for more details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download