LoginSignup
0
0

More than 3 years have passed since last update.

[React + TypeScript ] HTMLSelectElementのつもりなのに、Property 'options' does not exist on type 'HTMLElement'.

Posted at

課題

今日もTypeScriptから怒られた。

something.tsx
const months = document.getElementById('datetime_2i')
months ? (months.options[1].selected = true) : null
エラー
> Property 'options' does not exist on type 'HTMLElement'.

HTMLSelectElementのつもりなんだけどな。

結論

つもりなら書けと言うことらしい。
地味に時間取られる。

something.tsx
const months = document.getElementById('datetime_2i') as HTMLSelectElement
months ? (months.options[1].selected = true) : null

TypeScript素人故怒られまくる。
エラー解決するたびに只管メモします。

参考情報

Property 'selectedOptions','selectedIndex','options' does not exist on type 'HTMLElement'
https://sharepoint.stackexchange.com/questions/283252/property-selectedoptions-selectedindex-options-does-not-exist-on-type-htm

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