1

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.

0

1 Answer 1

4

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.

2
  • Any pointers for TSLint's [tslint] variable name must be in lowerCamelCase, PascalCase or UPPER_CASE (variable-name) ? it seems I can simply name it __ or add the disable rule comments. Oct 2, 2017 at 23:51
  • 1
    There's a tslint option for variable-name to allow leading underscores. palantir.github.io/tslint/rules/variable-name
    – tony19
    Oct 2, 2017 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.