4 ms·
Is it native in any significant way or is it just also transpiling but hiding that step enough to make it feel native? I guess this really hinges on how we defi
by Waterluvian 2y ago
Is it native in any significant way or is it just also transpiling but hiding that step enough to make it feel native? I guess this really hinges on how we define native.
I really want a runtime that actually leverages the type hints for JIT optimization.
- mrighele 2y agoBun uses JavaScriptCore (the js engine of Safari) so I doubt they are doing anything fancy with typescript types.
- dgb23 2y agoThere are certainly cases where type hints could be leveraged. But ultimately the way a JIT like Turbofan works is that it will do better optimizations if your JS code is already monomorphic (functions signatures, object fields and so on). Now TS sort of nudges you that way if you write simple TS code. But due to structural typing, expressive type golf features and the fact that TS is generally unsound I doubt it would be easy to leverage type hints much beyond that. Here are two talks that are very much related and give some insights into how difficult these kinds of problems are: https://thestrangeloop.com/2022/of-javascript-ahead-of-time-compilation-performance.html https://thestrangeloop.com/2022/of-javascript-ahead-of-time-... https://www.thestrangeloop.com/2019/typing-the-untyped-soundness-in-gradual-type-systems.html https://www.thestrangeloop.com/2019/typing-the-untyped-sound...
- wruza 2y agoDoes it make sense though? What should happen if a type hints a string and there’s a number in a received json? We gonna segfault?
- Waterluvian 2y agoYeah, exactly. You would need to handle deserialization like all the other strong/static languages. It would be an extra constraint for an extra layer of guarantee and ideally performance.
- wruza 2y agoI see, good point. Although my feeling is that typescript’s idea of a type system living on a separate plane was one of the greatest ideas of all time. Never felt so good about something that is basically js. With strict semantics like Rust/C++/Zig/Go it would be just a weaker clone of those with all the usual strings attached.
- Waterluvian 2y agoOh I fully agree. The ability to turn the type system off when you’re testing or hacking and want to be quick, or to gradually type a JavaScript project… it’s really the best. But I’ve got projects that are now as “correct” as possible, with full validation at deserialization and such and I just wish a compiler could take things an extra mile.
- mst 2y agoNative as in "if you import a .ts file it Just Works" I'm afraid. Roughly it strips the TS type syntax and hands the result off to JavaScriptCore - so it's not 'native' in the sense you might have been hoping for, and perhaps you'd find 'built-in' or 'seamless' or maybe 'out of the box' a better description of what it actually has. (I find the experience of -using- what it actually has to be excellent but 'native' is definitely an overloaded usage here)