Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i write typescript with in <Script> tag?

I am making a webview for my vscode extension. All the extension related code is in typescript and for webview , within Script tag of html, can i use typescript instead of javascript? If yes how?

like image 965
srikar kulkarni Avatar asked May 13 '19 06:05

srikar kulkarni


People also ask

Can we write TypeScript in HTML?

js file, also we can use script. js file in HTML page. For using script file in index. html file, use <script> tag to use script file, same as what we do for javascript file.

What can you put in a script tag?

The <script> Tag You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.

Can I use TypeScript instead of JavaScript in HTML?

You can't use TypeScript directly in a web page the same way you'd be able to use JavaScript -- that is, you can't add a <script> tag and point directly at a TypeScript file as your src, nor can you enter TypeScript between script tags. TypeScript has to be compiled into JavaScript for a web browser to understand it.


2 Answers

In fact you can not do this directly because the browser only understands JavaScript but you can do it but after you install the typescript-compile library.

like image 50
waseel almahri Avatar answered Sep 28 '22 09:09

waseel almahri


Typescript needs to be transpiled to javascript and browser only understands JS.

So you can include your Typescript code in html like this here but it needs to be traspiled into JS.

Read more about it here and this

like image 40
manish kumar Avatar answered Sep 28 '22 07:09

manish kumar