Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clarification on TypeScript's noUnusedParameters compiler option

Tags:

typescript

I'm trying to determine if this is, in fact, a bug before entering anything on GitHub.

With noUnusedParameters enabled, the TypeScript compiler will error on something like:

const foo = ['one', 'two', 'three'];
foo.forEach((item: string, index: number) => {
  // do something just with index, ignoring item
});

with error TS6133: 'item' is declared but never used. But while it's not specifically used, it is being used in that the second argument to the forEach iterator function is the index.

Am I missing something?

like image 746
icfantv Avatar asked Jan 16 '17 21:01

icfantv


1 Answers

There's no need to file an issue, as one already exists: with --noUnusedParameters how can i skip uneeded parameters.

tl;dr:
You can skip this error by prefixing the uninteresting arguments with underscore:

const foo = ['one', 'two', 'three'];
foo.forEach((_item: string, index: number) => {
    console.log(index);
});

Compiles fine.

like image 199
Nitzan Tomer Avatar answered Nov 13 '22 20:11

Nitzan Tomer