Como o Typescript pode ajudar seu projeto a crescer?

How can Typescript help your project grow?

TypeScript is a superset of JavaScript developed by Microsoft for scalability. A popular choice for IT companies and large projects around the world, it can help you grow if you know when to use it.

texto datilografado

Douglas Crockford said in his book “JavaScript has some good ideas and some very bad ideas”.

Without getting too technical, let's just say that JavaScript is prone to unexpected behavior. For example, a statement that compares whether 2 numbers are equal could potentially fail if the numbers are high enough (999999999999999 is the same as 10000000000000000 in JavaScript).

Another point of scorn is one of JavaScript's greatest strengths: its flexibility. JavaScript is permissive, which means that even if the code is not perfect, the engine tries to execute it by guessing what the developer intended. When it works, it's magnificent, but when it doesn't, it can produce strange results.

Case in point, the semicolon (;) in JavaScript has a very specific function: they act as an end-of-statement signifier, telling the engine when a block of code ends. But in JavaScript, they are mostly optional. You could write an entire program without semicolons and it would work perfectly. Once again, JavaScript is making educated guesses about where each statement ends up. Except that's not always the case.

Third-party libraries or specific engines may have a different opinion about where a declaration ends, which translates into erratic behavior. Code can run in one environment and generate an error in another.

Some of the worst offenders have been eliminated in newer versions of JavaScript. Other peculiarities were adopted by the community as shortcuts and resources. Finally, some popular libraries and frameworks have done their part in fixing the worst aspects of the language.

JavaScript and scaling

Peculiarities aside, JavaScript is here to stay. There are no other competitive browser scripting languages ​​on the market, and despite all its problems, it's a great language for beginners and professionals alike.

JavaScript is perfect for small projects or teams. When you have one or two developers working on a thousand lines of code, it's very easy to detect irregular behavior and eliminate it.

Unfortunately, JavaScript's quirks increase as products grow. What was originally strange behavior can quickly become a nuisance, extremely difficult to debug. The bigger the team and the bigger the product, the more you need to rely on stable, predictable technology.

Remember those educated guesses I mentioned earlier? Imagine that a developer on a team makes a mistake that goes unnoticed because the code works as expected. So, when the code is integrated into the project, the error still goes unnoticed.

As time passes, the project scales, but this time, the new code fails because it depends on the previous buggy code. Should be an easy fix, right? Perhaps, unless another aspect of the project depends on the outcome of this strange behavior; in which case changing it would break something else.

And so, a small, innocuous mistake snowballs into a full-blown crisis. We'd be telling a very different story if language didn't allow strange behavior in the first place.

Enter TypeScript

The JavaScript community is huge and there are hundreds of tools designed to prevent this type of situation. Still, some developers prefer to nip the problem in the bud, and that's where TypeScript comes in.

TypeScript is a superset of JavaScript developed by Microsoft and released in 2012. It has a strict syntactic approach that adds optional static typing to JavaScript. To avoid technical details, let's just say that TypeScript enforces some rules that make code more predictable and reliable.

Typescript was designed from the ground up to be similar to JavaScript but scalable. That's why, just like its predecessor, it is a multipurpose language that can be used to write client-side or server-side applications.

TypeScript is not a different programming language. Anyone who knows JavaScript can adapt to TypeScript with very little effort. It's as if an English speaker learned to write in a different style, rather than learning an entirely different language.

TypeScript code is transpiled to JavaScript, so it can run effortlessly in any environment that runs JavaScript. From an investment point of view, it is a low-cost initial investment, both in time and resources.

Remember that StackOverflow survey I mentioned earlier? TypeScript ranks as the third most loved programming language, right behind Rust and Clojure. It is the second most mentioned programming language when asked what technology developers would like to incorporate into their projects.

The reason for this is simple: TypeScript took over a decade of JavaScript and incorporated fixes that developers were begging for. To be fair, JavaScript gurus will have little reason to move to TypeScript. But it can save hundreds of hours of debugging and migraines for junior developers and large teams.

Think of TypeScript as an implicit communication tool. When a developer writes code in the language, other team members can be sure that nothing strange is happening behind the scenes. You can pick up and use the code without needing to check for abnormal behavior first.

And that's why TypeScript is such an excellent tool for scalable projects: its results are more reliable and the code is easier to understand. If a developer declares a variable to be a number, it won't magically turn into a string.

A few words of warning…

TypeScript is great, but it has its own set of problems. For one, it's harder to read because there's a lot more to declare compared to JavaScript. When working with unfamiliar code, lack of readability can slow down production time.

Second, TypeScript works best when all of its dependencies are typed. Unfortunately, this is not true for most third-party JavaScript libraries; so by using another dependency you are opening the door for weird behavior to come back.

That said, most developers slowly but surely adapt their libraries to a typed style. As a quick example, Angular and Vue 3, two of the most popular front-end frameworks on the market, have migrated to TypeScript.

Even with its limitations, if you're working on a large or scaled project, I hope I've made the case for TypeScript. This superset, young as it is, is gaining momentum with each passing year and has become a standard for IT companies across the world.

Source: BairesDev

Conteúdo Relacionado

O Rails 8 sempre foi um divisor de águas...
A GenAI está transformando a força de trabalho com...
Entenda o papel fundamental dos testes unitários na validação...
Aprenda como os testes de carga garantem que seu...
Aprofunde-se nas funções complementares dos testes positivos e negativos...
Vídeos deep fake ao vivo cada vez mais sofisticados...
Entenda a metodologia por trás dos testes de estresse...
Descubra a imprevisibilidade dos testes ad hoc e seu...
A nomeação de Nacho De Marco para o Fast...
Aprenda como os processos baseados em IA aprimoram o...
Introdução Quando se trata de desenvolvimento de software, a...
Milhares de sites são criados todos os dias. Não...
Os recursos de linguagem que serão incluídos na próxima...
JavaScript DataGrids se assemelham a planilhas do Excel e...
Você decidiu contratar um desenvolvedor JavaScript . Você quer...
A Microsoft anunciou recentemente a disponibilidade geral do interpretador...
A web está em constante evolução, e com ela,...
A Inteligência Artificial (IA) tem sido um tema cada...
Você já se sentiu frustrado com a complexidade de...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.