Transcript from the "Built on Typescript" Lesson
>> The other thing that it's important to understand about Deno is that it's TypeScript first. And in fact, let's look at the Deno project here. So let's just go out and take a look at their GitHub here. And let's go to their standard library. And if we look at their standard library here, let's take a look at HTTP.
[00:00:51] And and then he doesn't explicitly say it, but he's sort of implies that complex systems on the other hand need a structured language with the type system, okay. You may or may not agree with that statement. I don't know that I necessarily do. But there are some key reasons why you might want to consider TypeScript as your preferred language, especially for larger and more complex applications.
[00:02:00] Strongly typed languages are different. There's generally accepted patterns and practices that go into object oriented languages they've been around for a while. Things like the the Gang of Four's design patterns. And by the way, one of those Erich Gamma, who's one of the authors of the Gang of Four is one of the architects of vs code.
[00:02:23] So, there are some philosophical reasons there to adopt it. The other reasons are things like better tooling. So let us take a look at something real quick here. I am gonna go. Actually, we do not need to, let us just create a new file here and call it app.ts.
[00:02:43] And what I wanna do here is I'm going to pull in a module called Cosmos. And this is Azure's Cosmos DB TypeScript package. We're not gonna use it. I just want to use it to show you the benefits of writing things in TypeScript. And so this module is written in TypeScript here.
[00:03:03] And we'll wait for this to install here. Just a second. But once we get this, let's look at the tooling benefits that we get from this. So, what I wanna do here is import from and of course VS code is aware. It sees the different packages that we have here that can pull in.
[00:04:29] Even better though, is that we have this options, right but we don't know what these options are. But with TypeScript we do. And so it knows that these are the different options that you can gonna have and then we know what type they are. If we come over them again, it tells us what they are.
[00:05:02] The problem is currently with TypeScript, which is not a first class citizen, is that we have to transpile it or compile it to something else before it'll run. So for instance, if we did something like this message which is of type string says, Hello World. And then let's just log it out.
[00:05:43] And so to do that, we would then have to initialize our project as a TypeScript project with a ts config file, which I just did with tsc dash dash and let me clear out the terminal. And then that file is gonna have a ton of different I mean, this is every possible option here.
[00:06:00] But we actually don't need to change anything. We can just come to VS code and do like a Ctrl Shift B. And then we can select build, and it will just build for us based on that, ts config file. And it should give us an app.js file right, which looks like that and now we can run this this will work.
[00:06:22] And that's fine. But the problem is that as you have more and more files so like let's say you have a utils file here. A TypeScript file. Make sure that's in the right directory. And then, let's just add something here called const utils, all right. Then in order, we have to compile this too.
[00:07:04] And the way that we usually deal with this is you go to workspace settings. Let's see workspace settings in VS code and what you can do is you can say, I think it's files.exclude. There we go. And then we can come in here and just tell it like, these are called globs.
[00:09:08] Now I should note here that something that's kind of interesting about node is that so this app.js file, we can now run this with node, app.js and that will work. But node will execute any file. [LAUGH] It doesn't care. And so actually you don't even have to have an extension you just call it app and just say node app.
[00:09:31] Oops node app. There we go. So you can try this out just like take a file and change the extension to something else. I don't know like Git Smurf or something. And this will work. In Dino is actually the same way Deno doesn't care that the file extension.
[00:10:06] I'm not saying that any of this is a bad thing, maybe this is how it should be. But usually when you wanna have a TypeScript project, you now need to bring in gulp. And you need some sort of an a build process. And all I'm saying is these things can be tricky to set up, easy to mess up and kind of a drag.
[00:10:25] In Dino TypeScript is a first class citizen. And so, as you see, what that means is that all of that hackiness of compilation and where we put files and all that stuff, all that goes away. The TypeScript just is your code. And that's all there is.