Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i use TypeScript in place of JavaScript to make a Webpage? [closed]

Tags:

I'm actually a total newbie on programming, and i would like to learn how to make a proper webpage. Html, CSS and JavaScript is the basic trio for web programming according to what I've researched.

I've read TS is like a expanded version of JS which allows static type and many other functionalities but, If i start learning TypeScript and use it instead of JavaScript in a webpage it works as if it were JS?

Can I replace the JS place in a webpage with TS files?

TypeScript is a priority, since it's needed to an app I would like to code in a future. So, I would like to know whether start learning only TS or JS as well.

This is probably the most stupid question ever asked but I could not find an answer, Don't be so rough with me please.

like image 521
Faithoot Avatar asked Feb 25 '18 01:02

Faithoot


1 Answers

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. At a minimum you need a TypeScript compiler, but generally you're not going to manually compile TypeScript code and then copy and paste the output into a web page, so beyond just the compiler you're typically going to rely on having a development environment set up using something like Angular CLI or webpack that automates the task of compiling your TypeScript and building it into your web page.

I wouldn't say you have to learn JavaScript first, but I'd recommend learning JavaScript side by side with TypeScript, learning the differences as you go along -- quite often even when you're trying to mostly use TypeScript you'll end up having to do a little pure JavaScript here and there as part of the "glue" needed to put a project together.

like image 82
kshetline Avatar answered Sep 23 '22 13:09

kshetline