0

I want to write a function which will return below statement. The function is writen in .ts file. I am new to type script and still learning it.


function intitalizeApp() {    

  <React.StrictMode>
    <Loading />
  </React.StrictMode>,
  document.getElementById('root')
  
}

The problem i am facing is that show me red underline but the same code work fine when i am putting in .tsx file.

Please click to see the image

Can anybody point me why i am seeing red line when i am putting in .ts file or there is any other issue?

Raj
  • 37
  • 5
  • Did you look at your "problems" tab in the console (you have 5), or move your mouse over the warnings in the code to work out it out? – Andy Feb 26 '22 at 06:26
  • 2
    @Raj you need to name the file with .tsx to use jsx tags with typescript. In .ts files, those angle brackets get interpreted as being type assertions, not elements. See: https://www.typescriptlang.org/docs/handbook/jsx.html#basic-usage – Nicholas Tower Feb 26 '22 at 06:30
  • Rename file to `init.tsx` so it can use JSX. – Drew Reese Feb 26 '22 at 08:36
  • Yes, it worked after renaming file to tsx. – Raj May 29 '22 at 22:31

0 Answers0