How do i get rid of Property ‘getElementById’ does not exist on type ‘never[]’? [closed]

I have

let accountNumber = (document.getElementById("lash-phone") as HTMLInputElement).value;

inside a function in typescript react, but it’s throwing this error

Property 'getElementById' does not exist on type 'never[]'.  TS2339

and this same code works for other screens

Answer

TS can’t pick up the type of document by itself, so you can let it know what’s the type:

const lashPhone = (document as Document).getElementById('lash-phone') as HTMLInputElement;