Casting HTMLElement to HTMLTextAreaElement in Typescript

Image by Charles Davis from Pixabay

Scenario

Our constructor is expecting an HTMLTextAreaElement instance but document.getElementById() returns an HTMLElement .

Approach

const c: HTMLTextAreaElement =<HTMLTextAreaElement> document.getElementById('console')

Demo

See console.ts for the constructor implementation and index.ts for the actual demo.

Founder of Firefly Semantics Corporation

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation

More from Medium

Taking a Query Snapshot of a Firefly Semantics Slice Entity Store

A Walkthrough for fetching API

Top 9 Most Popular Angular JS Frameworks For The Year 2022!

Inputmode attribute in HTML — Display Appropriate Mobile keyboards