TypeScript - Getting Rid of Error: X is Declared, But Never Used

TypeScript - Getting Rid of Error: X is Declared, But Never Used

The problem

If you have set tsconfig setting noUnusedParameters to true, the compiler will give an error when you have defined a function, but you're not using all the parameters. If you remove the unused parameter, then the function doesn't have the same signature and errors will occur elsewhere in the code. For example, a callback function could have three parameters, and you are interested in the second one.

export const onChange = (selectedValue:string, index: number) => {
  index + 1
}

The solution

It is a bit embarrassing, but I had been doing TypeScript development for 1.5 years until I encountered the solution. The only thing you need to do is to replace the parameter and its type definition with a pair of curly brackets, like this:

export const onChange = ({}, index: number) => {
  index + 1
}

I hope this tip is as useful as it was for me!