DEV Community

Discussion on: In defense of TypeScript

Collapse
 
vinceramces profile image
Vince Ramces Oliveros

[2] Keep in mind that TypeScript is not a static typed language but a strong typed one

Whether it is static or strongly typed, it transpiles down to javascript. which would be a horror if there are no type validations or null checking.

const add = (first:number, second:number) => first + second;

to

// Transpiles down to support IE(lol)
var add = function(first,second){
return first + second;
}

There are libraries that does type validations.
TypeScript is good if I'm building a complex and large scale JavaScript Applications. But for a small apps, I'll use JSDoc and manually put input validation to ensure I got those values correctly.

Collapse
 
damxipo profile image
Damian Cipolat

I agree with the result of transpilation of TS, it does not give a high quality code, not to mention how it does the handling of numbers. It is a big problem not to worry about which is the true code that V8 will receive

Collapse
 
stojakovic99 profile image
Nikola Stojaković

Just add Babel into compilation process. TypeScript's compiler is not so great at generating code for the browser, especially if you use some newer features.

Collapse
 
stojakovic99 profile image
Nikola Stojaković

Regarding type validation, I often use class-validator.

Sure, if you're working on something small TypeScript may be like pulling Howitzer from the garage to go to the grocery store.

Collapse
 
vinceramces profile image
Vince Ramces Oliveros

Perhaps you could discuss this with FP Peeps 🤷🏻‍♂️ for the class-validator. They don't use classes but use Interface(abstract class).