Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
4 events
when toggle format what by license comment
Nov 13, 2023 at 21:41 comment added GoodJuJu I like this method because anyone coming across the code would clearly see what the type is. If you wanted, you could always combine the ? & the as keyword. So you could do something like const modalRoot = document.getElementById("modal-root") as HTMLElement; & then when you need to access it and its properties do: modalRoot?.foobar.
Feb 26, 2021 at 10:47 comment added Oluwaseyitan Baderinwa I did apply it and it seemed to be the only way to fix the error. And the cheatsheet gives more details as to why this method is recommended. Btw, the HTMLElement type is Element|null type so I don't think it'll give an error. I already tested it
Feb 25, 2021 at 7:27 comment added Hari Kishore yeah, that might work, but we call that as inline typecasting, i.e., we're just changing type in place. still I feel, if there is null values, that is, if the div doesn't exist, it will still give null. and the typecasting null as HTMLElement might give error. did you try applying changes?
Feb 24, 2021 at 20:53 history answered Oluwaseyitan Baderinwa CC BY-SA 4.0