Compiling TypeScript to JavaScript1:32
and we run that. And that should give us access to, what that'll do is it'll generate a JavaScript file directly attached to our TypeScript file here. And what we can see here is that it has turned our const greeting with the type of string into a normal JavaScript variable and has logged it out. So here's our TypeScript file and here's our JavaScript file. And then we can obviously execute this JavaScript file as we would any other one. And there are a whole heap of flags we can give to the TypeScript compiler to let us do things. But the easier way to do that is actually to create a TypeScript config file.
Configuring tsconfig.json3:22
There are other strict checks and linter checks that you can configure in the tsconfig.json. Basically it tells you what every single property does, what it's used for, and it's very, very searchable. So I recommend you check this out when you're setting up a TypeScript project and configure it for your needs. Generally, this file, which I'll include in the description, should be a good start for you. So what this allows us to do is if you have a tsconfig.json file present, which I do now, I can rerun this TypeScript compile and then hop back into here. And in lesson zero, I no longer need to give it a file name.
Executing TypeScript with Deno5:25
We could also run node in lib/hello-laracast.js. That's how you do it after you compile normally. The other option we have here is deno. So deno is a secure runtime for TypeScript built in Rust. You've probably heard about it before. For basic scripts like this, you can also use deno, except it's going to break down a little bit if you're using React or Vue or Express or some larger framework that might not be deno compatible. But for a simple script like this, you can also just run deno run hello-laracasts, and what that'll do is deno has its own TypeScript configuration, and it'll do its own checking.
ts-node and Webpack Options5:51
But for a simple script like this, you can also just run deno run hello laracasts, and what that'll do is deno has its own TypeScript configuration, and it'll do its own checking and then just execute the code directly. So that's another way you can execute code. ts-node is the most common because it doesn't have the baggage of deno. If you're doing something on the front end, you're most likely using Webpack to compile your code and do tree shaking and all that stuff. Webpack has excellent TypeScript support, and the Webpack documentation has a TypeScript section, which is very easy to follow and very straightforward. You basically just configure how to match a TypeScript file, what to exclude, what to
