DEV Community

Cover image for JavaScript vs TypeScript. Why We Should Learn TypeScript?

JavaScript vs TypeScript. Why We Should Learn TypeScript?

hiro9108 on January 17, 2021

What is TypeScript? Hello, I am a student in Vancouver, Canada and studying web development. In this article, I will show you "How to us...
Collapse
 
matjones profile image
Mat Jones

Good article dude. TypeScript is awesome. Basically, TypeScript prevents you from using things the wrong way, at compile time, which is one of its greatest strengths. Especially when vanilla JavaScript has such a wacky type system.

Collapse
 
jamesthomson profile image
James Thomson

It also plays nicely with most IDE's so Intellisense is much more valuable, especially in very large codebases.

Collapse
 
0815fips profile image
0815fips

You can configure your jsconfig.js properly, add JSDoc and *.d.ts files to be as safe as in TS.

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

@matjones @jamesthomson @rammina
We all can agree that TS is a must for a couple of things but did you know that you can use TS in two different ways? Check this out 😄

Collapse
 
kooiinc profile image
KooiInc

I have been programming java-/ecmascript (ES) for 28 years now and never felt the need to use (the hassle of) TypeScript.

It's relatively easy to check the input for a function, e.g. by contract:

function fooContract(a, b) {
  return  a?.constructor === Number && 
     b?.constructor === Number;
}

function foo(a, b) {
  if (fooContract(a, b)) {
    return a + b;
  }

  throw new TypeError(`function foo => expected 2 Numbers`);
}

foo("40", 2); //=> TypeError
foo(32); //=> TypeError
foo(40, 2); //=> 42
Enter fullscreen mode Exit fullscreen mode

To check the type of (nearly) everything in ES, I deviced a small module.

Collapse
 
rammina profile image
Rammina

Great introduction to Typescript! It is not only informative, but also cleanly formatted in a way that beginners can understand.

I can definitely agree with your points, Typescript makes coding less punishing, especially in a larger project. I just love the type safety that it gives you as well as the amazing IntelliSense. While there is boilerplate, it makes up for it by reducing mistakes and bugs, as well as improving code quality.

However, Typescript has downsides, which I discussed here:
dev.to/rammina/downsides-of-typesc...

I hope it will help people when they think about when NOT to use Typescript.

Collapse
 
caleb_whittaker profile image
Caleb Whittaker

That was a very concise article and well formatted for beginners such as myself. I've been learning to code with JavaScript for about a year now and the amount of times that I've received type errors or other bugs that took me longer than I'd like to admit to find makes me wish I had started to learn TypeScript sooner.

Collapse
 
ananddevspace profile image
Anand

Nice Article, Keep Writing 👏

Collapse
 
mehrdadarman profile image
Mehrdad Arman

Nice article... short and useful

Collapse
 
raimundo82 profile image
João Raimundo

Jsdoc solves the motivation problem. By the way, it's bad practice to name a function that adds two args pikachu

Collapse
 
imran2part profile image
imran2part

Nice article please write for us ts with react

Collapse
 
jamesli2021 profile image
jamesli2021 • Edited

Good student pickup TypeScript. Go language and TypeScript are perfect since both feels similar.

Collapse
 
syntaxbreaker profile image
SyntaxBreaker

It's a superb introduction to Typescript. Keep writing about it! 😊

Collapse
 
kravamax profile image
Max Kravchenko

Thank you for my first meeting with TS

Collapse
 
jln profile image
JLN

nice article

Collapse
 
shreyazz profile image
Shreyas Pahune

Very helpful 👍🏻

Collapse
 
nazimudheen_ti profile image
NAZIMUDHEEN TI

Tanx.. Dude