DEV Community

Omer Elbaz
Omer Elbaz

Posted on • Updated on

How I began using TypeScript

I hope this post will convince you to give TypeScript a try if you haven't already. It really is an amazing tool that can make your life as a developer much easier.
So, without further ado, let's get started!

What is TypeScript?

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. That means that you can use all of the features of JavaScript, plus additional features that are not available in JavaScript. These include things like type annotations, classes, interfaces, and modules.
TypeScript is designed for development of large-scale applications and trans-compiles to JavaScript. As TypeScript is a superset of JavaScript, existing JavaScript programs are also valid TypeScript programs.
TypeScript may be used to develop either client-side or server-side applications. There are several popular frameworks that can be used with TypeScript such as Angular, React, Vue, Node.js etc.

Why use TypeScript?

There are several reasons why you might want to use TypeScript over plain JavaScript. The first reason is that TypeScript helps you catch bugs early on in the development process. This is because TypeScript is a typed language, which means that you have to declare the types of variables before using them. This can help prevent errors such as assigning a string value to a variable that is supposed to be a number.
Another reason to use TypeScript is that it makes your code more organized and easier to maintain. This is because TypeScript uses modules and namespaces to group related code together. This makes it easy to find the code you're looking for and helps prevent name collisions between different pieces of code.
Finally, TypeScript is just plain fun to use! It has all of the features of JavaScript plus additional features that make development more enjoyable. Once you get used to the syntax, you'll find that working with TypeScript is a breeze.

How to get started with TypeScript?

Now that we've gone over some of the reasons why you might want to use TypeScript, let's talk about how to get started with it.
If you're just getting started with TypeScript, I recommend checking out the official documentation on the website: https://www.typescriptlang.org/.

What benefits I've found in using TypeScript

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It adds optional types, classes, and modules to JavaScript. TypeScript is designed for development of large applications and trans-compiles to JavaScript.
TypeScript is a typed superset of JavaScript. This means that any valid JavaScript code is also valid TypeScript code. In addition to being able to use all of the JavaScript language features, TypeScript also adds some additional features that can be very helpful when developing large applications. These additional features include optional types, classes, and modules.
One of the benefits of using TypeScript is that it can help you become a better programmer. This is because TypeScript adds static type checking to JavaScript. This means that you can catch errors early and prevent them from happening in the first place. Static type checking can also help you write better code by making it easier to refactor code and catch bugs early on.
Another benefit of using TypeScript is that it can help you become more productive. This is because TypeScript speeds up development by providing things like autocompletion and error checking. In addition, the TypeScript compiler can help you find errors in your code before you even run it. This means that you can fix errors faster and avoid having to debug your code later on.
Finally, one of the benefits of using TypeScript is that it helps you create better software. This is because TypeScript makes it easier to create well organized and maintainable codebases. In addition, TypeScript helps you avoid common software development pitfalls such as tight coupling and global state. As a result, you can create software that is more robust and easier to maintain in the long run.

How my workflow has changed since using TypeScript

Overall, I'm extremely happy with TypeScript and would recommend it to anyone who is looking for a better way to write JavaScript.

What difficulties I've encountered while using TypeScript

Another difficulty I've encountered is that TypeScript can be picky about code style. This can make it difficult to integrate TypeScript into an existing codebase that uses a different code style. For example, if your codebase uses tabs for indentation and TypeScript expects spaces, you'll get errors. It's important to be aware of these differences and make sure your code adheres to the requirements of both TypeScript and your project.
Finally, I've found that using TypeScript can slow down development due to its compile-time type checking. This means that every time you make a change to your code, you have to wait for the TypeScript compiler to run before you can see the results. This can be frustrating when you're used to the instant feedback of interpreted languages like JavaScript. However, there are ways to speed up compilation time, such as using the watch flag or setting up incremental compilation in your IDE.
Overall, I think that the benefits of using TypeScript outweigh the difficulties. The language has come a long way in recent years and there are now many resources available to help you learn and use it effectively. If you're starting a new project or looking for a typed alternative to JavaScript, I would recommend giving TypeScript a try.

Overall, how TypeScript has positively impacted my life

One of the most important things that TypeScript has helped me with is learning how to utilize interfaces. Interfaces are a powerful tool that can help you make your code more maintainable and easier to understand. However, they can also be tricky to use. TypeScript has helped me understand how to use interfaces effectively and has saved me a lot of time when working with legacy code.
Overall, I am very happy with how TypeScript has positively impacted my life. It has made me a better programmer and has provided a great tool for catching errors. I would highly recommend it to anyone who is looking to improve their programming skills.

In short, TypeScript has made my life a lot better! I no longer have to deal with the tedium of constantly having to check my code for errors, and I can now focus on actually creating things instead of worrying about whether or not my code will work.

Check out our website BLST
Join the discussion in our Discord channel
Test your API for free now at BLST!

Top comments (12)

Collapse
 
thethirdrace profile image
TheThirdRace

This article would have greately benefinited from more research and proof-reading.

The amount of misinformation is simply staggering...

you can use all of the features of JavaScript, plus additional features that are not available in JavaScript. These include things like type annotations, classes, interfaces, and modules.

classes and modules are Javascript features, not Typescript.

TypeScript is designed for development of large-scale applications

You can use it just as well for very small apps too, there's no limitation

Another reason to use TypeScript is that it makes your code more organized and easier to maintain. This is because TypeScript uses modules and namespaces to group related code together. This makes it easy to find the code you're looking for and helps prevent name collisions between different pieces of code.

Typescript doesn't make your code more organized. You can definitely develop a Typescript program that is screwed up from top to bottom. Typescript only does what you tell it to.

Also, Typescript official documentation suggests using module over namespace. From what I could read about namespace, I would be very worried about how tree-shakeable it is, which is probably not at all, and it most likely will polute the global space, which is an absolute no no...

Another benefit of using TypeScript is that it can help you become more productive. This is because TypeScript speeds up development by providing things like autocompletion

I'm pretty sure Javascript has that too... And that would be the IDE providing that, not the language itself.

TypeScript helps you avoid common software development pitfalls such as tight coupling and global state.

It's like saying a pen is helping you write better essays... the tool definitely doesn't prevent you from screwing yourself up...

Another difficulty I've encountered is that TypeScript can be picky about code style. This can make it difficult to integrate TypeScript into an existing codebase that uses a different code style.

Typescript doesn't care one bit about your code style. I have no idea where you got that from...

For example, if your codebase uses tabs for indentation and TypeScript expects spaces, you'll get errors.

Again, Typescript doesn't care one bit about your code style. I use tabs in Typescript without any problems whatsoever, I can use tabs and spaces on the same line too if I want... are you sure you're not confusing Typescript with eslint?

I've found that using TypeScript can slow down development due to its compile-time type checking. This means that every time you make a change to your code, you have to wait for the TypeScript compiler to run before you can see the results. This can be frustrating when you're used to the instant feedback of interpreted languages like JavaScript.

This is somewhat true and false at the same time. Yes, Typescript is slower than Javascript because it needs to compile, but we're talking of less than a 1 second difference... Most of the tools will instantly refresh your browser page automatically and you might even keep the state intact.

To qualify that of slow down is splitting hair at best.

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

Modules, classes, code completion - all available with plain JS.

Also, TS will not magically make you a better developer. It will merely set you on the path of getting better at TS, and possibly learning about some new concepts you may not have come across before (but these can be easily picked up without TS). Getting better at anything is down to you, not your tools.

Personally I cannot stand TS. My programming journey started out with strictly typed languages - only much later did I come to JS... and what a breath of fresh air it was! So much easier and quicker to get things done - much greater freedom. But, of course, with great freedom comes great responsibility - you need to understand how JS works and be aware of the pitfalls. It's a different mindset for sure, but well worth getting into.

TS for me just takes all the fun out of JS, and is largely just a crutch for those who don't want to change their habits when coming from strictly typed languages. I think it's better to work with JS instead of fighting against it with ever increasing amounts of tooling.

Collapse
 
alvi_niloy profile image
Alvi Adhikary Niloy

No offense, but in my opinion typescript will only be a realistic solution when popular browsers natively support typescript along/instead of Javascript. Even typescript gets compiled to javascript when run.

Collapse
 
cuongnguyen11 profile image
cuongnguyen11 • Edited

in 2020 my client required TS for new react project, so I had to use it, after this project, I really love it :D

 
jzombie profile image
jzombie

They're both relatively similar and are interchangeable in a lot of regards.

Collapse
 
jzombie profile image
jzombie

Yeah, they are one of my favorite features as well, and I like the fact that you can extend them (plus do other weird stuff with them if you want to).

 
leob profile image
leob

Reading this post I would be more convinced by his enthusiasm than by his actual arguments - but that's not to detract from this post, his level of enthusiasm is rather convincing indeed ! :)

Collapse
 
leob profile image
leob

It's not completely circular - interfaces are a TS feature, but they're also a generic concept ... :)

Collapse
 
dessiebieri profile image
DessieBieri

Is it worth learning ? Wet Cupping Calgary