LoginSignup
3
0

More than 1 year has passed since last update.

【TypeScript】@ts-ignoreと@ts-expect-errorの違い

Posted at

共通点

以下のように記述するとどちらも次の行の型エラーを無視できます。

// @ts-ignore
// @ts-expect-error

スクリーンショット 2023-05-11 21.38.07.png

画像のようなエラーが発生している場合に以下の画像のようにするとエラーが出なくなります。

スクリーンショット 2023-05-11 21.38.48.png
スクリーンショット 2023-05-11 21.39.23.png

違い

次の行にエラーがない場合の挙動に違いがあります。
@ts-ignoreは何も起こらないのに対し、@ts-expect-errorはエラーとなります。

エラーのあった<List />を削除すると@ts-expect-errorではエラーが出ています。

スクリーンショット 2023-05-11 21.40.45.png
スクリーンショット 2023-05-11 21.40.02.png

参考

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