tc39 / proposal-type-annotations

ECMAScript proposal for type syntax that is erased - Stage 1
https://tc39.es/proposal-type-annotations/
4.27k stars 47 forks source link

Cost benefit analysis #43

Open LifeIsStrange opened 2 years ago

LifeIsStrange commented 2 years ago

A non erased javascript support for type would enable features such as type reflection and reified generics, which improve the expressivity of the language and make it more on par with modern languages. However, currently this proposal is not making any use of the types despite them needed to be parsed or at least properly ignored.

The remaining stated benefit is that this support might (to be defined) reduce transpilation needs for e.g TypeScript. However if I am understanding correctly, in all intellectual honesty this proposal should state that it is not a free lunch and that the cost of transpilation is offsetted to the Javascript parser/interpreter, which must now properly ignore those unused type informations. Therefore you are offloading a one time cost (server side) to N billions of clients times. While support for runtime type reflection might justify such added cost, without it this proposal seems like a net performance loss for end users. There already exist plenty of fast server side TS transpilers such as SWC, esbuild, etc which make the proposal benefit seems even less interesting. What do you think about this?

hinell commented 1 year ago

I agree with @boehs and hope this won't be merged as well. My two cents:

shaedrich commented 5 days ago

@fabiospampinato - yes, but this would also allow you to remove an entire step from your tool-chain. A step many consider to be particularly laborious to deal with. I like the idea of types, I even like the idea of Typescript (incrementally), but the Typescript compiler often annoys the hell out of me.

You can't have your cake and eat it, too 😂 You want functionality (type checking) just isn't part of the language (JS), so there's (for good reasons) just no way around using tooling. That's the bargain.

Also, putting the "I went away from JS to TS, now I have trouble with TS, so JS must fix this for me" on the non-TS JS developer community just doesn't seem right.

Most standard TypeScript syntax is supported, and reaching out to .d.ts files would still be feasible for cases when syntax cannot legally fit the constraints we're looking at.

That would beg the question: Who would write these files?

define that syntactic space within JavaScript for type-systems and other tools to safely exist in a way that engines can know how to ignore them.

So, JS's future to excel in ignorance? Not sure if that's something, I'd pride myself with. There have been other proposals (for example, compartments, parser augmentation, import attributes, etc.) that would have more benefit to the JS community specifically as a whole, not just TS devs who don't like TSC. Might be interesting to @giltayar

A browser which knows how to strip TypeScript types for example would have to keep up to date with the TypeScript implementation which could add new syntax every quarter.

It sounds like a terrible idea that every time, TypeScript adds a new syntax, that isn't stripped away by the specs of the scope this proposal,

Additionally, every time, TypeScript adds new syntax, everyone who works without the TS compiler now has two options:

do we want it to be a language that HAS to be run with tools and can't just run "natively"? I for one, do not. […] without needing to run complex toolchains that they (and, frankly, most js developers) cannot comprehend or configure.

JS can still run without any toolchains. It is TS who can't. Stop making TS problems JS ones.

such a specification wouldn’t be able to make breaking changes, which TS needs to do with some regularity.

Well, client-side scripting is built around stable back compatibility. This probably shouldn't be circumvented.

mend the existing rift we have between developers who write TypeScript and runtimes that execute JavaScript.

So, TS opened the rift but JS must close it? I guess, you've got the cart before the horse here.