I’ve had this thought one and off over the last few years since I started using TypeScript back in 2015 actually. What if Web browsers natively supported TypeScript?
If Web browsers could natively support TypeScript without needing a build step first, would it be possible and secondly, would it be performant? As in, you just build your site and instead of
.js files you reference
It turns out, someone else had the same idea back in 2016 when they created an issue on the Chakra GitHub repository requesting native TypeScript support. The team had discussed the possibility but they were against it because TypeScript isn’t a web standard and they believe WebAssembly is a better option.
We now know based on Deno experimenting with native TypeScript Support in its Node.js successor that it might be easier said than done. As it currently stands, the TypeScript compiler has some performance issues due to the overhead of type checking.
While Deno has done a fantastic job attempting to get native TypeScript support in its Node successor, they still experienced issues in regards to type checking incuring a performance hit. The idea was floated in the above linked issue, but rewriting the type checker in Rust while undoubtedly providing performance improvements would open up a can of problems.
TypeScript is being constantly iterated on and improved, any type checker written outside of the TS core would need to be updated and patched almost constantly. That’s a lot of work just to have your own individual and more performance type checker.
Secondly and most importantly, the amount of work to rewrite the TypeScript type checker into Rust would be an astronomically huge, expensive and time-consuming endeavour.
Seeing first-hand the problems that Deno has had in regards to performance and native TypeScript support, the dream of browsers natively supporting TypeScript will probably always remain a dream, unless the TypeScript team themselves move TypeScript to Rust (which is doubtful).
I like this idea, but it is not a far-fetched dream. Native typescript support in browsers would likely mean ignoring all type-checking, and not doing the type-checking. This will speed up development greatly!