How TypeScript Makes You a Better JavaScript Developer

Original Source: https://www.sitepoint.com/typescript-better-javascript-developer/?utm_source=rss

TypeScript

What do Airbnb, Google, Lyft and Asana have in common? They’ve all migrated several codebases to TypeScript.

Whether it is eating healthier, exercising, or sleeping more, our humans love self-improvement. The same applies to our careers. If someone shared tips for improving as a programmer, your ears would perk.

In this article, the goal is to be that someone. We know TypeScript will make you a better JavaScript developer for several reasons. You’ll feel confident when writing code. Fewer errors will appear in your production code. It will be easier to refactor code. You’ll write fewer tests (yay!). And overall, you’ll have a better coding experience in your editor.

What Even Is TypeScript?

TypeScript is a compiled language. You write TypeScript and it compiles to JavaScript. Essentially, you’re writing JavaScript, but with a type system. JavaScript developers should have a seamless transition because the languages are the same, except for a few quirks.

Here’s a basic example of a function in both JavaScript and TypeScript:

function helloFromSitePoint(name) {
return `Hello, ${name} from SitePoint!`
}

function helloFromSitePoint(name: string) {
return `Hello, ${name} from SitePoint!`
}

Notice how the two are almost identical. The difference is the type annotation on the “name” parameter in TypeScript. This tells the compiler, “Hey, make sure when someone calls this function, they only pass in a string.” We won’t go into much depth but this example should illustrate the bare minimal of TypeScript.

How Will TypeScript Make Me Better?

TypeScript will improve your skills as a JavaScript developer by:

giving you more confidence,
catching errors before they hit production,
making it easier to refactor code,
saving you time from writing tests,
providing you with a better coding experience.

Let’s explore each of these a bit deeper.

The post How TypeScript Makes You a Better JavaScript Developer appeared first on SitePoint.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *