3 ms·
Yes. TypeScript doesn't have a sound type system and it comes with a lot of baggage: * Using hashtables in TypeScript relies on the representation of JavaScrip
by constexpr 11y ago
Yes. TypeScript doesn't have a sound type system and it comes with a lot of baggage:
* Using hashtables in TypeScript relies on the representation of JavaScript objects with strings as properties. Emulating JavaScript's in-memory representation in an ahead-of-time compiled language isn't a good idea for performance reasons.
* TypeScript only has a single number type (double) which is pretty slow if you actually need to work with integers. JavaScript VMs do a lot of work to figure out which numbers are integers using information that's only available at runtime. Using explicit integer types means the generated code is a lot tighter.
* A lot of existing TypeScript code uses structural typing to model dynamic type contracts present in today's JavaScript code, but this is usually a loosely-typed approximation and not something that a compiler can rely on. It's more just to improve tooling for developers.
* TypeScript uses exceptions which are hard to emulate efficiently in native code.
* I want to be able to add certain things and extend the language, so I don't want to limit myself to TypeScript. For example, I'm considering a preprocessor for conditional compilation and something similar to C#'s unsafe syntax for pointer manipulation.
- pookeh 11y agoAll these reasons in Typescript are intentionally designed so that it's easy to work with the rest of the JS ecosystem. Good tooling + rapid prototyping is a strength not a weakness.
- freditup 11y agoBut they are weaknesses when designing a languages to compile to wasm. I love TypeScript and the Microsoft team has done a fantastic job with it, but that doesn't mean it's the right tool for this particular job.
- constexpr 11y agoI don't consider the design of TypeScript a weakness at all. TypeScript is really well designed and is great at what it does. The type system they came up with is pretty optimal for modeling real-world JavaScript code. But the tuning they did around the JavaScript ecosystem means it's not a great language to use for generating efficient native code. I started ThinScript in part for exactly that reason. I want good tooling and rapid prototyping, just for native development instead of web development. That requires a different set of trade-offs and design decisions.
- smt88 11y agoIt sounds like your issue here is that TypeScript is a superset of JavaScript and comes with JavaScript's complications/inefficiencies. Do you agree with that assessment?
- constexpr 11y agoYes. As the parent comment said, you could try to to choose a subset of TypeScript that's relatively efficient to help avoid some of the issues with JavaScript. The problem is that the TypeScript language itself lacks certain primitives required for efficient ahead-of-time compiled code (integers, for example).