DEV Community

Discussion on: Future Javascript: Types may finally be coming to Javascript

 
smpnjn profile image
Johnny Simpson

It's simply because adding types to Javascript wholesale would break half of the internet. It would be a massive language change and would affect many components of Javascript. This change is a slow step in that direction, but it's non-committal. This can be implemented with no damage to already existing websites, and then tc39 can decide how to proceed from there. It's incremental steps.

The main benefit to this is of course it reduces the need to compile. Currently TypeScript requires you to compile your files into standard Javascript so they can be run in the browser or on a Node.JS/Deno server. With this, there is no need to compile anymore. TypeScript files are valid Javascript, the types are just ignored.

Therefore TypeScript can still enforce its rules and checks, and take out the compile step - meaning a faster overall development time for developers.

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️ • Edited

So the proposed change really affects TS then (making the compiler read type info from comments) - complicating development further (as mentioned above)? Honestly, all this faffing around would be gone if developers just accepted JS for the language it is, and work with it instead of fighting against it. I've been coding for 38 years (26 professionally) and - quite honestly, when I first came to JavaScript it was a breath of fresh air after working within the straitjacket of strongly typed languages.

Thread Thread
 
smpnjn profile image
Johnny Simpson

That's why it's annotated, and not enforced. Annotated types mean you can still write your Javascript with types, and it'll be valid Javascript, or you can write it without types, to get the flexibility you describe.

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️ • Edited

So much yak shaving just to avoid adapting your mindset to using a language that doesn't have strict typing. I'll never understand it.

This proposal just feels like TS creators trying to dig themselves out of a hole that they created for themselves

Thread Thread
 
mateusmento profile image
Mateus Sarmento • Edited

Dude you seem a bit stoned reading from your comments. But I don't understand your unnecessary complain with a proposal for types in javascript. To be honest I agree with you to say that the type annotations would not be meaningful for the javascript language itself if "treated like comments", which actually is my complain here. Having type check in runtime would open the doors for something like multiple dispatch for functions which would be wonderful for implementing ad-hoc polymorphism and being able to simply overload functions... I really think you are either being unreasonable or just really stoned. This browser extension thing was hilarious...