... there is zero advantage in shipping TypeScript to the client. As compiling to JS will make the payload smaller.
Not having to compile the typescript would lead to simpler development workflows and that would be a pretty big advantage in my opinion. The size difference is extremely small and will not make a measurable difference. If we really cared about size, we would compile to some sort of AST/binary format.
Always wondered why we aren’t doing a binary format. Seems like it wouldn’t be so hard to unravel and the speed up would be fantastic. Still holding out hope for webasm to take hold
An extra compile step clientside, instead of doing it in advance, is adding pointless work clientside. The user gets a longer startup time. That isn’t a good thing.
It isn’t going to simplify the workflow on any real world website. As that website will need to support older browsers. Even if older is only one month old. It means you can only reliably use the latest features in TypeScript … if you precompile it before shipping.
Finally whilst I have tonnes of faith in the TypeScript team. You are asking for one implementation to rule them all. It’s like everyone using Chromium with no alternative.
Cause then we would need every browser vender to support the full ecmascript spec and the full typescript spec. Which I don't really see happening. It would be awesome if they did not going to lie I love ts alot more than js. But I would find it unlikely for them to support 2 scripting engines like that.
Correct me if I'm wrong but isn't the full JS spec technically a part of the full typescript spec? Considering that TS is a subset *superset of JS and all?
So what I'm getting at is that the typescript engine can parse both typescript and javascript in the browser and therefore you just need the one engine to handle either file types.
All js programs are mostly valid ts programs. There are some programs that are not I am on mobile but if you Google q bit you can fine one.
Also the optimizer for ts would be really different from a js optimizer I think, because ts has the type information so it could in theory not do all the type magic js does. I also don't know dick about writing interpreters. So I am sure some one will uhm actually me any minute now.
A compiler may not be able to optimize out type checks completely, but it could generate code which tests whether an object is of expected type, performs operations optimized for that type if so, and otherwise uses code that can handle arbitrary types. Not as big a win as eliminating the type checks, but still pretty big nonetheless.
I'm not sure about nobody, it could be nice for rapid prototyping without requiring to setup a build system, but yes in production nobody that cares about their users would use it.
39
u/DuncanIdahos9thGhola Jun 28 '21
why can't we just have <script language="typescript"> ?