0

I was wondering if it is possible to utilise @babel/plugin-transform-typescript to translate typescript code to javascript code when the function is called during user interaction, for example, when the user clicks on a button. My goal is to show the source code on the page as you can see below. So far I managed to put it only in typescript; however, I want to also be able to view it in JSl

The code that I have right now: enter image description here

The problem is that I get this error when I click on the button that triggers the function: enter image description here

Do you have any suggestion how to resolve this issue? Any help will be greatly appreciated.

  • Typescript already compiles into JavaScript. So maybe I'm not understanding what you're trying to do, but you shouldn't need any other package, it does that on its own. – Taylor Burke May 08 '20 at 19:34
  • I know it does compile it to Javascript; however, my goal is to show the source code on my page. The thing is I want it to be also in Javascript so I am looking for a solution. @TaylorBurke – Le Tuan Anh May 08 '20 at 19:37
  • You can compile your code to JavaScript using the typescript compiler. See specification here. https://www.typescriptlang.org/docs/handbook/compiler-options.html – Sonu Bamniya May 08 '20 at 19:51
  • 2
    Looking at [this question with a title similar to your error](https://stackoverflow.com/q/53427901/215552) it seems you need to use [Babel Standalone](https://babeljs.io/docs/en/next/babel-standalone.html)... – Heretic Monkey May 08 '20 at 19:52

0 Answers0