When and how to use it
TypeScript is best for large-scale projects and enterprise-level applications. Using it for small-scale projects with one or two JS files may be overkill.
One way is to let your IDE do that for you, usually via an extension to the IDE. The way you use the extensions can vary greatly. They can provide a UI to configure the various options, or they can use a tsconfig.json file to do so. And they can also provide a button for the conversion, do it automatically on save with their own file watchers, or provide a command to use it via the command line.
The importance of static typing
With TypeScript, most of the errors that you’re commonly getting at runtime in a dynamically typed language are gone, because now these errors are being shown to you before you can run the program, so you are forced to fix them if you want to run the code. If you’re debugging something at runtime, you probably need a debugger, which you might not have access to or fully understand how to use, so it’s much harder to do that at runtime, with so many other things to consider. You have to track down where in your code that is actually happening from, and there are so many possible issues when you’re not catching these bugs while compiling.
And when you’re working on large-scale software that’s going out to clients and users, you want to make sure that you caught and fixed all those bugs, and that you’re getting them in your IDE before you actually go to the software.
Work smarter, not harder
The idea is that if you give your IDE more information about your code, it can do more work for you. If you can have your IDE carry a lot of the weight and do a lot of the work, you’re saving yourself both time and money, to actually code. You want to get that done as fast and precise as possible, and that is the core advantage of TypeScript.
TypeScript comes with a lot of other really great features too, but the one that most people like about TypeScript is that typing is completely optional. Some people might think that having to declare the types will be a pain, but it’s really not that difficult. And being optional, you can have two people working on the same code, one person working strictly with types, and the other person not using them at all, and, while it may not be the ideal solution, their code will still be compatible. There may be potential issues, of course, but the concept is that it’s optional, so if it doesn’t make sense to declare types, you don’t have to do that. And, you can still use the other advantages of TypeScript. In other programming languages that are actually truly statically typed, you would, of course, have to do that.