LoginSignup
0
0

More than 1 year has passed since last update.

【TypeScript】型アサーション

Posted at

今日の学び

// これはダメ
const hoge = document.querySelector('.hoge') as HTMLElement;

// これでオッケー
const hoge = document.querySelector<HTMLElement>('.hoge');

型アサーションは任意の型へ強制的に変更できるが、型安全性が保証されないので極力使用しないこと。

参考文献

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