2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

とりあえずTypeScriptのコード書いて挙動を確認したいだけなのに、eslint警告「TS6133: 変数名 is declared but its value is never read.」が出てdisableしても1つ目の変数しか抑制されない

2
Posted at

はじめに

  • 仮でコードを書いてみたい

問題

  • これでは最初の変数しかエラー抑制されない
/* eslint-disable @typescript-eslint/no-unused-vars */
/* @ts-expect-error テスト用 */

const b: boolean = true;

// TS6133: n is declared but its value is never read.
const n: number = 1;
  • これだとtsの静的解析全く効かない
/* eslint-disable */
// @ts-nocheck

const b: boolean = true;
const n: number = 1;

解決

  • こうすれば少ない追記で参照される可能性を残せるので、tsの型エラーは出つつも変数が使用されていないエラーは出なくなる
export const b: boolean = true;
export const n: number = 1;

終わりに

  • 静的解析のパーサがどうテキストを解釈しているかわかっていない
2
0
0

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?