ECMAScript Proposal: Types as Comments
github.com
github.com
Is there some other advantage? Easier debugging on the client, I guess, but proper source maps do that pretty well already. I dunno, this just seems to be making a complex language more complex for not much gain.
That said, if the runtime actually used the types for safety or performance, I could maybe see some value added there.
I would enjoy the flexibility to ship types but personally don't have any need for it. Seems like "boiling the frog" for type-checking in the browsers to me but I personally like the idea of encouraging more typing in native JavaScript.
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.
The types aren't for end users.
You just advocated for developers using tool to validate the types, but that already exists in the form of typescript.
Warnings also don’t matter, as live sites don’t report debugger warning to the host servers (and even if they did they’re unlikely to be fixed).
The only reason to add the type syntax to js is if that type system is going to be enforced.
We don’t want another series of wat presentations about the bizarre JS type system, and we don’t want to add things to the language if there isn’t value in doing so.
The types are for end users insofar as they help ensure that the site operates correctly. Them not being enforced means that you also can’t be notified (through window.on error or whatever it is) that your site has a type bug in it.
Any type syntax added to the JS language must be able to pay for itself, and making it so you can paste some subset of typescript into the JS console is nowhere near justification.
If it was though, how well or poor is it working there?
Bundling then becomes an optional step that can be implemented for a production build. If it's only JavaScript then a simple `deno bundle index.ts` without any configuration should suffice.
TypeScript is the main language that I program in every day, and I don't see the advantages of this proposal outweighing the disadvantages.
Bold to speak for the group of devs likely to have the most variety. Personally I hate twiddling with build systems and will happily write worse code to avoid it so what I do know.
It feels so liberating not having to deal with the usual mess of JavaScript toolchains.
Of course, that would defeat the whole purpose of the ever-continuing TC39 standardization process, so it’s not going to happen.
But ignoring the types is actually worse than “not being helpful”, as it both locks in the current syntax (unlike claims it does provide space for experimentation), and it means that engines cannot in future start enforcing the types specified with this syntax.
<script language="typescript" />
As long as node and chrome are so dominant, we're probably not going to see big shake-ups in JS that aren't driven by Google themselves.
JS is flexible, you can cover up a lot with polyfills, but not completely different syntax. Doing that without Google's buy in would create a rift in the internet that would either end with browser specific web pages, or with the complete loss of power for the committee that sets the ECMAScript spec as JS officially goes from being a language that is defined by a spec to a language defined by a canonical implementation (in this case V8).
https://www.typescriptlang.org/docs/handbook/jsdoc-supported...
https://github.com/giltayar/proposal-types-as-comments#why-n...
Various good reasons, like how it would hinder TS evolution and you'd end up having to compile TS to whatever older version of TS the slowest implementors support anyways.
But one interesting point is that type analysis is for the developer's benefit. What is the imagined benefit and behavior of pushing type analysis over the wire with the code to be run on the end-user's machine?
Is that even a question?
If more people adopt TS because it's native in browsers, producing less bugs means more user satisfaction.
If you push TS source that you didn't bother tsc'ing on your machine because hey it runs on the client, does it simply fail to run for the user even though the program would have worked? I don't see how pushing TS source is better than pushing compiled JS.
Nothing precludes Typescript from becoming another ECMA spec. It's just not going to be ECMAScript.
Nothing precludes Microsoft from allowing Typescript to run directly in the browser either. Nothing. Just that nothing forces any other browser to support Typescript as well.
Nobody has to follow standards if they don't want to, in practice...
I think typescript is a temp hype just like jQuery, useful for many, but a few people can just do the vanilla JavaScript way.
There are many reasons this concept of “unenforced type syntax” is flawed, and from the threads for the MS proposal there are already JS consoles/CLIs that support TS.