DEV Community

Matthew Harris
Matthew Harris

Posted on

What does typescript add onto JavaScript

Hello everyone today I am here to discuss and here your comments on what typescript adds to JavaScript and what cases it should be used in.

In my personal opinion and just recently switching from JavaScript to typescript I can definitely say typescript is amazing and should be used in a lot of places.

One of the main places I think should use typescript is in npm packages as it can help debugging with type safety.

Although I do believe JavaScript still has a place being used to develop websites with pure html, css, and js. The reason i say this is because I believe it is easier it interface with then typescript as you skip the compiling step.

My main point is that if you use JavaScript for developing npm packages or just developing in general, you should give typescript a shot. If you need help developing a tsconfig file you can use my tsconfig as a baseline.

If you have anything else to add please let me know, as I would be glad to add more info to the post

Have a nice day and happy programming

Top comments (6)

Collapse
 
lorenzojkrl profile image
Lorenzo Zarantonello

TypeScript is a game-changer when you work in a professional environment!

As long as you code alone, you know pretty much everything about your app. You can easily get away without it. I am writing an Angular tutorial and guess what? In many examples, I don't use TypeScript, or I just use simple types.

When you work in a team or when you get some code from other teams the fun begins!
It is not only about you, you don't quite know what you will get from an API or the backend. You should look it up yourself, assuming you know where to look and the documentation is good enough. And even when you do look for info, you are likely to forget the shape of the response.

Angular ships with TypeScript and from anecdotal experience React is also embracing it.

TypeScript is an incredibly useful tool. It is up to you to use it at the right time and in the right context.

Collapse
 
hacker4world profile image
hacker4world

Typescript adds more features to javascript like interfaces, custom types enums and more

In my opinion typescript shines the most when working on big projects as it makes it harder to produce hard to catch bugs

Collapse
 
ernestvonmoscow profile image
VanPonasenkov • Edited
  1. Leaner documentation. I think when you write types in the code itself it makes your documentation clearer and easier to read. It's based on the fact that when you write plain JS, you have to specify argument names, their types, etc., in the docs. With TS you can focus on describing behaviour.
  2. Better IDE/Text Editor support. Makes your life so much easier when you don't have to go to docs every time you forget the exact name of the method/function you're looking for
Collapse
 
lexlohr profile image
Alex Lohr

Type checking should be another part of your testing pyramid, even below unit tests: you're testing your expressions for type soundness in order to avoid surprise type coercion.

Collapse
 
jaecktec profile image
Constantin • Edited

I believe that's what the test pyramid refers to as 'staticliy typed test'

Collapse
 
lexlohr profile image
Alex Lohr

Also, you can test your types using the // @ts-expect-error pragma.