TypeScriptの型エラーとの付き合いかた
一括で@ts-expect-errorを設定する
@ts-expect-error は @ts-ignore とことなりエラーが起こることをマークしているのでエラーが起きなくなった時はコンパイルエラーになる。
code:sh
npx suppress-ts-errors
@ts-expect-error の指定を削除する
// @ts-expect-error TSxxxx でコメントが付与されているものを一括で削除する。
code:sh
# {/*\n\s+?// @ts-expect-error で始まるJSXのコメントを1行に正規化する (必要な場合のみ)
find . -type f -not -path './node_modules/*' \( -name '*.ts' -o -name '*.tsx' \) | xargs gsed -i -E -z 's#\{\/\*\n(\s+)// @ts-expect-error#\{\/\* @ts-expect-error#g'
# @ts-expect-error を含む行を全て削除する
find . -type f -not -path './node_modules/*' \( -name '*.ts' -o -name '*.tsx' \) | xargs gsed -i '/@ts-expect-error/d'
無視した型エラーのサマリーを取得する
ts-expect-error の数を種別ごとに集計する
code:sh
find . -type f -not -path './node_modules/*' \( -name '*.ts' -o -name '*.tsx' \) | xargs grep --color -rin ts-expect-error | grep --color -oE 'TS\d+' | sort | uniq -c | sort -rnk1