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.

--

--

Ole Ersoy
Ole Ersoy

Written by Ole Ersoy

Founder of Firefly Semantics Corporation

No responses yet