Unexpected identifier In Typescript HTMLFormElement

Viewed 185

let forms = document.querySelector('.new-item-form') as HTMLFormElement ;


const typess = document.querySelector('#type') as HTMLSelectElement;
const tofrom = document.querySelector('#tofrom') as HTMLInputElement;
const details = document.querySelector('#details') as HTMLInputElement;
const amount = document.querySelector('#amount') as HTMLInputElement;

forms.addEventListener('submit' , (e:Event)=>{
   e.preventDefault()

   console.log(
    typess.value,
    tofrom.value,
    details.value,
    amount.valueAsNumber,

    )
}) 

i am trying to get value from my dom but it shows an error Uncaught SyntaxError: Unexpected identifier

I don't know what is the reason of those error

1 Answers

You can't use TypeScript as it is in browser. You have to transpile it with Babel or compile it with TSC. Also you can use ts-loader if you are using Webpack.
As the definition of TypeScript says:

TypeScript compiles to readable, standards-based JavaScript.

Source: TypeScript npmjs.com

If you are new to TypeScript you should check their documentation first.

Related