DEV Community

Cover image for Why I'm Learning Typescript
Anna Baker
Anna Baker

Posted on

Why I'm Learning Typescript

One of the things that I like most about TypeScript is that it is a superset of JavaScript. This means that any valid JavaScript code is also valid TypeScript code. This makes it very easy to get started with TypeScript. Another thing that I like about TypeScript is that it has static typing. This means that you can catch errors at compile time, rather than at runtime. This makes for much more stable and robust code.
One of the challenges that I have faced while learning TypeScript is understanding the type system. The type system in TypeScript is very powerful, but it can also be quite complex. It has taken me some time to get a good understanding of it, but I am still learning new things about it all the time.
Overall, I am really enjoying learning TypeScript. It is a great language that has already helped me to improve my JavaScript skills. I am looking forward to continuing to learn more about it and using it in my future projects.

What is Typescript?

TypeScript is a free and open source programming language developed and maintained by Microsoft. It's a typed superset of JavaScript that compiles to plain JavaScript. TypeScript adds optional types, classes, interfaces, enums, generics, and more to JavaScript. These features can be used by the TypeScript compiler to provide type safety for your code. TypeScript code can be compiled to ECMAScript 3, ECMAScript 5, or ECMAScript 6 (also known as ES2015) code.
If you're familiar with React, you may have used the createreactapp CLI tool to create a new React project. The createreactapp tool uses TypeScript by default. This is because React is developed using TypeScript and it's recommended that you use TypeScript for React projects.
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It gives you type safety, objectoriented programming, and other benefits that the JavaScript language lacks. If you're familiar with React, you may have used the createreactapp CLI tool to create a new React project. The createreactapp tool uses TypeScript by default. This is because React is developed using TypeScript and it's recommended that you use TypeScript for React projects.

Why I'm Learning Typescript

I've been meaning to learn Typescript for a while now. I'm finding it really helpful in understanding JavaScript concepts, and it's also just really fun to use. I'm looking forward to using it more in the future.
I first heard about Typescript when I was looking for ways to improve my JavaScript skills. At the time, I didn't really understand what it was or how it worked, but the idea of being able to type out my code and have better control over my variables sounded appealing. After doing some research, I decided to give it a try and I've been hooked ever since.
Typescript is a superset of JavaScript, which means that any valid JavaScript code is also valid Typescript code. This makes it easy to get started with, as you can gradually add Typescript features to your existing code base without having to rewrite everything from scratch.
One of the things I love about Typescript is that it forces you to be more explicit about your code. For example, if you try to access a property on an object that doesn't exist, you'll get an error. This might seem like a pain at first, but it actually saves you a lot of time in the long run by catching errors early on.
Another great thing about Typescript is the support for type annotations. This allows you to specify the type of a variable, which can be helpful for catching bugs before they happen. For example, if you have a function that expects an number as an argument, you can annotate the function with:

function(num: number) { ... }

If someone tries to call this function with a string instead of a number, they'll get an error telling them that they're using the wrong type of argument. This is extremely useful for catching errors in large codebases where there are many different types of data being passed around.
Overall, I'm really enjoying learning Typescript and I'm looking forward to using it more in the future. It's helped me improve my JavaScript skills and has made me more aware of potential errors in my code. If you're thinking about learning Typescript, I would highly recommend it!

How I'm Learning Typescript

I'm currently using the TypeScript Deep Dive book as my primary resource for learning Typescript. This book does a great job of explaining all of the features of Typescript in a clear and concise manner. Additionally, the book includes a number of exercises that help to reinforce the concepts that are being taught.
In addition to the TypeScript Deep Dive book, I've also been using the official TypeScript documentation as a reference. The documentation is extremely thorough and covers every aspect of Typescript in great detail. While it can be a bit daunting at first, it's a great resource to have on hand when you need to look up something specific.
I've also been making use of online resources such as the TypeScript Playground (https://www.typescriptlang.org/play/) and the TypeScript Handbook (https://www.typescriptlang.org/docs/handbook/). These resources are extremely helpful for trying out code snippets and seeing how various features of Typescript work.

Overall, I'm finding that learning Typescript is not as difficult as I initially thought it would be. With the help of some great resources, I'm slowly but surely getting up to speed with this powerful programming language.

Latest comments (55)

Collapse
 
youssefmic profile image
Youssef-mic

Hello, for me learning typescript is largely unnecessary because I work alone and I hate oop maybe you can say I am biased but doesn't matter I am ok with javascript as it is

Collapse
 
annabaker profile image
Anna Baker

Thank you for your opinion! I respect that you are happy with JavaScript as it is, and as long as you are ok with that's great! For me, I find that learning TypeScript is helpful because it forces me to think about my code in a different way. I also enjoy the challenge of learning something new. :)

Collapse
 
youssefmic profile image
Youssef-mic • Edited

Thanks a lot

Collapse
 
elsyng profile image
Ellis • Edited

Imho, ts is not a language. It's a "typing+" tool for js. And as such, I find adding some ts features into your js is good. Ts has a lot of obscure features, which I think do more harm than good. I think one should not try to apply all ts features religiously. But that's me :o)

One very big benefit of React (for instance) is, it allows you to use js / ts minimally, I find.

Collapse
 
annabaker profile image
Anna Baker

I agree, ts is a good tool, but that one should not try to use all of its features all of the time.

Collapse
 
beraliv profile image
beraliv

Hey!

Thank you for the article!

If you didn't see github.com/type-challenges/type-ch..., you can give it a try, it helped me a lot in the last several years. Especially helpful if you want to dive into challenges and learn more things in details.

The only thing that I didn't like is the lack of detailed explanation

Collapse
 
annabaker profile image
Anna Baker

Thank you so much for the kind words! I'm glad you found the article helpful.

I'm always looking for ways to improve my writing, so I appreciate your feedback.

Collapse
 
deinnalynch profile image
DeinnaLynch
Collapse
 
lexiebkm profile image
Alexander B.K.

My reason for learning TS :

  1. Angular uses it. Although I am still using React, Angular is still interesting to learn (and use).
  2. NestJs uses it. As a Node.js framework), NestJs is heavily inspired by Angular for the architecture. However, because I am still learning TS, I suspend my learning this Node.js framework, until my knowledge in TS is adequate.
  3. Several other useful/interesting libraries use it.
Collapse
 
annabaker profile image
Anna Baker

It's great that you're learning TS! I'm sure you'll be able to use it in many different frameworks and libraries. Keep up the good work :)

Collapse
 
chrishunterjohnson profile image
Chris Hunter-Johnson

I like typescript - the only issue I have is getting it to work with the Theme file for material-ui

Collapse
 
apimike profile image
Mike Rozner

Simply put, it's a great article.

Collapse
 
annabaker profile image
Anna Baker

Thanks!

Collapse
 
polenj86 profile image
Maciej

Hi,
I also struggled at the beginning when I started learning typescript, it might be annoying at the beginning but now after 3 years of using it I'd never go back to vanilla JS, I simply love the fact of finding errors at compile time instead of finding them at runtime.
Anyway everyone should use it because it makes you think "better" on your code

Collapse
 
annabaker profile image
Anna Baker

You're so right! It can be frustrating at first, but learning typescript is so worth it in the end. It's helped me write much cleaner and more error-free code.

Collapse
 
eshimischi profile image
eshimischi
Collapse
 
joelbonetr profile image
JoelBonetR ЁЯеЗ

Thank you, never heard about that, seems useful for learning purposes and toying around (I'm not confident enough on mutators to use that in a serious project though ЁЯШЕ)

Collapse
 
vishalraj82 profile image
Vishal Raj

Good. Here is the typescript boilerplate repo
dev.to/vishalraj82/getting-started...
Hope this helps.

Collapse
 
eshimischi profile image
eshimischi

Take a look github.com/gcanti/fp-ts, more complex project with TS

Collapse
 
annabaker profile image
Anna Baker

Thanks I will :)

Collapse
 
eshimischi profile image
eshimischi • Edited

it's recommended that you use TypeScript for React projects.

You own personal interpretation, because community never said that, you are free to use whatever you need to. For instance, in my web company (>500 employees) we do use JS (Vue, corporate framework, etc) because no one except couple of guys (me included) knows TS, so itтАЩs definitely not a good idea about using it widely. Hiring engineers with TS skills isnтАЩt/wasnтАЩt a main task.

Collapse
 
joelbonetr profile image
JoelBonetR ЁЯеЗ

That's currently the mainstream, specially in frontend ЁЯд╖ЁЯП╗тАНтЩАя╕П

Collapse
 
eshimischi profile image
eshimischi

WasnтАЩt talking about trends..

Thread Thread
 
joelbonetr profile image
JoelBonetR ЁЯеЗ • Edited

Neither do I, it's just the current state of the market since long time ago.

Trends are spikes in between that and they may cope the market till certain point (see React for example, with more users than Angular, Vue and Svelte together) or set a tendency growing steadily (like TS) or keep living in the community hype for some time without reaching a worth mentioning piece of the market (see Tailwind).

All of them are in a certain situation for good reasons.

Thread Thread
 
eshimischi profile image
eshimischi • Edited

Again, i wasnтАЩt talking about it, calm down. Anna stated that тАЬit is recommended to use..тАЭ not the case, you can use JS/TS whatever suits you the best. Period

Thread Thread
 
ashleyjsheridan profile image
Ashley Sheridan

I think the point is still valid. It is recommended to use Typescript where possible over Javascript. It does catch some issues at development time, provides way better feedback on variables and instances in your IDE (and it's 2022, who isn't using an IDE by now?), and it makes you think about the way you write your code.

Of course, as with anything there are ways round all of that if you really want to ignore best practices. You can use any for pretty much all your type declarations, you can force wrong types in at runtime (which won't be caught by the transpiler), and you can just disable warnings given by your IDE.

Typescript aims to enhance Javascript, and bring some more modern concepts to the language, such as you'd find on C#, for example. You don't have to use Typescript, but it's recommended that you do because it will make your life easier.

Thread Thread
 
joelbonetr profile image
JoelBonetR ЁЯеЗ • Edited

Agree, still the amount of things you can learn at once is limited.
In my experience with newcomers they tend to focus into solving warnings and errors on types (which need to be defined) and less into actually learning the language (JS) API, hence the delivery is poor and individuals last longer to be able to get to an efficiency point.

Learning JS first (if you do it properly, of course) allows people to focus on what's most important first (learning the language, the huge API and the quirks of the language) because with that you can do things, protect yourself from runtime errors by experience, and then move forward to TS to get all those extra benefits.

I can recommend to jump into TS directly if you already have experience with another language that's strong-typed such Java or C# to make things easier though.

Thread Thread
 
ashleyjsheridan profile image
Ashley Sheridan

I have noticed the opposite. Newcomers tend to focus more on Javascript, as Typescript is seen as more difficult and harder to learn. I've noticed this with plenty of other languages too. PHP has quite a similar aspect in that there are the traditional older approach to writing code with it, versus the newer approach with stricter typing and cleaner architectural thinking (this is going back over the past decade and more of PHP). There is some level of pushback from developers who've only learned the older way, who don't see any value in more modern approaches. Personally, having worked with a lot of other languages with strict types, like C++ and C#, I come down on the side of preferring stricter typing in "loose" languages, because it's one step towards writing cleaner code.

For Typescript, one thing that it does introduce with the transpiler is the option to ignore some quirks of Javascript. This is made even easier when you are using something like NPM to bundle any required polyfills according to your build targets. After all, why re-invent the wheel. We're not developing in the days where IE6 was running ramshod over the specifications, the browsers are much more closely aligned in terms of support for features. Sure, some browsers might not support certain things, like Chrome doesn't support MathML, and some browsers implement many things that aren't officially part of the spec (unfortanetely have to highlight Chrome there again), but by and large, we're in a better position that we were 12+ years ago.

Jumping to TS from a position of knowing another strongly typed language does make sense. Microsoft did take a lot of what they learned creating C# in their creation of Typescript.

Collapse
 
shriekdj profile image
Shrikant Dhayje

I also started learning typescript

Collapse
 
annabaker profile image
Anna Baker

I'm glad to hear that you're also learning Typescript it's a great language to know.

Collapse
 
rkallan profile image
RRKallan

Is it correct to call TS a language?
Because the engine is JS, only before the engine runs it adds some checks.
Is zend framework or Laravel a language?

Thread Thread
 
shriekdj profile image
Shrikant Dhayje

I think i will call TypeScript as Javascript Compiler Just like for C or Cpp There is compiler called mingw or clang

Collapse
 
prathmeshb profile image
рдкреНрд░рдердореЗрд╢ | Prathmesh ЁЯМЯ

Can i skip javascript and learn typescript instead? does it will be problem

Collapse
 
andrewbaisden profile image
Andrew Baisden

No cutting corners you have to learn the fundamentals of the language first. It's like trying to learn React before you learned JavaScript ЁЯШВ

Collapse
 
prathmeshb profile image
рдкреНрд░рдердореЗрд╢ | Prathmesh ЁЯМЯ

LoL

Collapse
 
eshimischi profile image
eshimischi

ItтАЩs more like learning a new language without grammar and rules

Collapse
 
nicvazquez profile image
Nicol├бs Vazquez

Since TypeScript is a superset of JavaScript, naturally you have to know JavaScript first. TypeScript simply adds properties, specifically statically typed, to your JavaScript code, making it easier to maintain.

Collapse
 
prathmeshb profile image
рдкреНрд░рдердореЗрд╢ | Prathmesh ЁЯМЯ

ok got it

Some comments may only be visible to logged-in visitors. Sign in to view all comments.