1
0

More than 3 years have passed since last update.

Typescript: X is Declared, But Never Usedの解決方法メモ

Last updated at Posted at 2019-10-30

X is Declared, But Never Usedというエラーが出ることがある。

以下のような例だ。

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

// val is Declared, But Never Used

回避するには、変数の代わりに空のオブジェクトを使えば良い。

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

エラーが消えるはずだ。

この方法は可読性を高めてくれるので、気に入った。

参考
https://www.triplet.fi/blog/typescript-getting-rid-of-error-x-is-declared-but-never-used/

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0