[RAILS] [React + TypeScript] Property'options' does not exist on type'HTMLElement'.

Task

I was angry with TypeScript today as well.

something.tsx


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

error


> Property 'options' does not exist on type 'HTMLElement'.

I'm thinking of HTMLSelectElement.

Conclusion

It seems that you should write if you intend. It takes time soberly.

something.tsx


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

TypeScript amateur gets angry. Make a note every time the error is resolved.

Reference information

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

Recommended Posts

[React + TypeScript] Property'options' does not exist on type'HTMLElement'.
eclipse package org.springframework.boot.web.servlet.support does not exist
I stumbled while learning Rails on Cloud9 ~ Oops VFS connection does not exist ~
UriComponentsBuilder does not encode "+" depending on spring version
[Error] ActiveRecord :: NoDatabaseError FATAL: database does not exist
About error PG :: UndefinedTable: ERROR: relation "XXXXXX" does not exist
Note: Memory Analyzer does not work on Mac OS
Push notification permission pop-up does not appear on iOS14