Casting HTMLElement to HTMLTextAreaElement in Typescript

Ole Ersoy
1 min readJan 23, 2020

--

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.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ole Ersoy
Ole Ersoy

Written by Ole Ersoy

Founder of Firefly Semantics Corporation

No responses yet

Write a response