TypeScript is superior to JavaScript
About a year ago (since 2020), I started to use TypeScript. Then I decided I won’t use JavaScript for anymore.
TypeScript saved me many headaches and made me more confident when refactoring code. When I was using JavaScript, I wouldn’t know the mistakes I made about imports until it runs that part of the code. I remember I would see undefined error, when I check code, I would see I made mistakes.
But not with TypeScript. First off, the refactor tool with IDE (vscode) is much better with TypeScript. Because of TypeScript, IDE refactor tool can help me make the right changes without me going though file name changes manually. Secondly, I would see import error at compile time before running the code. I don’t think checking if code has import errors by running code is reliable because some code do not get run if you don’t visit every page in the app.
When I was using create-react-app with TypeScript, compiling the code would make the import error surface. Now my preferred framework is Nextjs, it only compile one page at time if you run dev mode. In this case, I would use `tsc — pretty — noEmit` command and it will check all the imports in the code comprehensively.
An additionally benefit of TypeScript is when you read codebase, you can see the type of function parameters.
In summary, TypeScript makes refactor much easier and helps you make less mistake during refactor, and make it easier to read codebase.