|
|
|
|
|
by vbezhenar
1555 days ago
|
|
Browser could build optional type support (for example with warnings), so you can leverage it and skip all packaging stuff. And sending few percent of JavaScript is not an issue. It's gzipped well and it's not what will slow down the website. For example I really love that I can just write modern JavaScript and just send it to the browser and it works. Serious websites of course will use minifiers and stuff, but for some small sites it's unnecessary burden. |
|
The effect of unenforced type annotations is that sites will end up writing code that is incorrect but works.
Any future attempt to enforce the types will break that content, and so cannot reuse the : syntax for type annotations, but browsers will continue to have to support it.
Mode switches are also not the solution: strict mode is responsible for a huge amount of complexity in the ES spec, and many annoying edge cases in JS implementations. The only reason I was ok with strict mode is the removal of |this| coercion, which could only be done via a mode switch. No other changes in strict mode would have warranted the mode switch.
Adding type annotations to JS would not require a mode switch as it is a purely additive feature (as let and for(of) were), but adding the burden of the syntax without actually adding the semantics makes absolutely no sense - it burns the prefer type annotations syntax, it adds complexity to the language, complexity to the engines, and provides no actual improvements to the ergonomics of the language.