Kickstart Your TypeScript Set Up 6 exercises

TypeScript's Relationship with JavaScript

Before diving into TypeScript, let's take a moment to talk about its foundation— JavaScript.

JavaScript is primarily a front-end language that allows your browser to come to life. If you're working in the back-end or with Node.js, you are also working with JavaScript.

The JavaScript ecosystem is m

Loading explainer


00:00 Before we talk about TypeScript, we really need to talk about JavaScript because without JavaScript, then TypeScript would not exist. TypeScript is just a set of syntaxes on top of JavaScript that help you build stronger, more performant, more robust applications.

00:19 And so TypeScript really is just a couple of extra little tweaks on top of JavaScript. And in order to run TypeScript code, most of the time you're gonna need to compile it down to JavaScript. In other words, strip out all of that sugar, turn it back into JavaScript, and then you can run your code. So you might be thinking,

00:38 why would I bother writing in TypeScript when I could just write in JavaScript? Because that's the stuff that's actually gonna get run. Well, when TypeScript was invented, it was invented because the tooling for JavaScript was kind of crap. This is a tunnel recording about 10, 11 years ago. And back then you had IDEs

00:56 that sort of worked with JavaScript, but you didn't have things that you had in other type languages like autocomplete and like checking that you're actually passing the right thing to the right function at the right time. That meant that as your applications got bigger and bigger and bigger, then actually JavaScript was really, really hard to work with.

01:15 And if you had to do any like refactors, let's say you had to change the way a function was called throughout your application, you would have to manually go through and check every individual piece of code or everywhere that function was called. And so people actually started like writing their code in C Sharp amazingly

01:33 and trying to turn it into JavaScript. And so C Sharp, this thing called Script Sharp, which I'll link to below, this was actually one of the first prototypes of something like TypeScript, where you could write your code in a strongly typed language that had autocomplete and type checking, all this sort of stuff, and actually transpile it down into JavaScript that would run in the browser.

01:53 The team at Microsoft were actually asked to like productize this and say, maybe we could turn this into something. And then someone at Microsoft had the great idea of saying, why don't we just make our own little language, which is closer to JavaScript in origin, but can still let you just transpile it down into JavaScript.

02:12 And so TypeScript was born. And 10, 11 years later, it's still being run by the same small team at Microsoft. Writing JavaScript now, 11 years after TypeScript was invented, feels like you're going back in time about 11 years. Your tools immediately just get a lot worse. You lose autocomplete,

02:30 you lose a sense of security when you're coding, and it makes refactoring bloody impossible in JavaScript apps. With TypeScript, you can take your entire project of code, whether that's a million lines long, you can check it with a TypeScript compiler, with a TypeScript CLI, and it will tell you whether you have any errors in your code.

02:50 Those errors might be, you've passed the wrong thing to a function, you're trying to access a property that doesn't exist, or the function you're calling might be undefined in this position. I've written applications with JavaScript and with TypeScript, and I've actually been at the heart of some companies like driving their way towards TypeScript, because I was so sick of working in JavaScript.

03:09 When I moved to TypeScript, I felt my velocity improve because my tooling was just so much more powerful. Often with JavaScript, I would have to try out some piece of code there and then go and check it in my browser to see if it was actually working. Then I'd find some stupid typo that I had written, have to go back to the JavaScript, modify it, go back.

03:28 With TypeScript, I could see my stupid typo right in the editor, and the editor would actually tell me, and I'd be less likely to even make it because I'd mostly be just working with autocomplete. And when you think about TypeScript versus JavaScript, you should be thinking about the power of your tooling. Do you want your tools to be as powerful as possible? And yes, this means that you will need

03:47 to compile your TypeScript code down to JavaScript. So you will need some kind of bundling step, but if you're working in web applications, if you're working even in Node as well, you will need some kind of bundling step anyway these days. So if you're bundling anyway, why not use TypeScript as well? The vast majority of web developers

04:06 or developers that I've met and work with and spoken to at conferences, they have gone to TypeScript and are never looking back. And for me, working in JavaScript feels like working in the dark ages. But with TypeScript, I feel like I'm working in a modern, powerful IDE, and I can't wait to show you more about it.