7 ms·
Ask HN: Is it possible to compile TypeScript to Golang?
Typescript lets me write the complex logic, but the Node concurrency model being single-threaded is very limited.
So ideally I would want to have Typescript running in Golang. Is there such a possibility?
- bkq 4y ago>Typescript lets me write the complex logic What is it about Go that prevents you from writing this complex logic?
- crop_rotation 4y agoNo, it is not (nor does it seem feasible). Why not just spin up multiple workers?
- thesuperbigfrog 4y agoIt sounds like you need a language that supports stronger types and concurrency. There are many good programming languages that might work if neither Go nor Typescript individually would meet your needs. I recommend examining the following to see if they would work better for you: Ada: https://learn.adacore.com/courses/intro-to-ada/index.html https://learn.adacore.com/courses/intro-to-ada/index.html Elixir: https://elixir-lang.org/ https://elixir-lang.org/ Java: https://docs.oracle.com/javase/tutorial/ https://docs.oracle.com/javase/tutorial/ Rust: https://doc.rust-lang.org/book/ https://doc.rust-lang.org/book/ All of them have excellent support for concurrency and strong typing to various degrees that help you to write complex logic quickly.
- ch_sm 4y agoElixir doesn‘t have support for static types built in.
- giaour 4y agoIt has support for type annotations, though, and tools like dialyzer can check for type errors much like TypeScript does: https://elixir-lang.org/getting-started/typespecs-and-behaviours.html https://elixir-lang.org/getting-started/typespecs-and-behavi...
- avinassh 4y agoInteresting choices. Are there any languages which have concurrency semantics like Go?
- mholyland 4y agoThere are many languages with libraries that can use CSP (Communicating Sequential Processes)[0], but some popular languages that have it in the core libs are: Golang, Crystal and Clojure. [0] https://en.m.wikipedia.org/wiki/Communicating_sequential_processes https://en.m.wikipedia.org/wiki/Communicating_sequential_pro...
- aristofun 4y agoTs is dynamically typed unfortunately. And also this implies the whole js library to be made thread safe. But the good thing is A. Horizontal scalability is far better approach for most usecases anyway B. Nodejs is so performant youd rarely beat it with other GC languages in real applications.
- ch_sm 4y ago> Ts is dynamically typed unfortunately What do you mean, specifically, with this statement? The point of TS is to give JS static types.
- aristofun 4y agoThat you can’t transpile dynamic language into a static one. If you call ts a statically typed language -> you dont know ts :)
- deleted 4y ago[deleted]
- fathyb 4y agoNo, the Go threading runtime is fundamentally incompatible with JavaScript's event-loop model. TypeScript does not define runtime semantics, JavaScript does, and it's built to run in a single-threaded environment. You cannot use it to leverage Go's coroutines unfortunately.
- karmakaze 4y agoYou can get the semantics of coroutines and no parallelism by setting GOMAXPROCS=1, either via environment variable or set in the program initialization.
- fathyb 4y agoIt would remove the benefit of running on Go. It would be less efficient than v8 + libuv because your TypeScript on Golang runtime wouldn't be as fast as v8 + JIT to run the application code which is now written in a language built for dynamic dispatch.
- alexbezhan 4y agoI don't need Javascript runtime semantics. I just want to use Typescript.
- Ecko123 4y ago[dead]
- pc_edwin 4y agoThis is not directly related to question but I would suggest using go just for those use cases. Programming in general has become a lot more abstract and standardised so with some exceptions (C/rust) you can easily use multiple languages without incurring much if any costs. Something else you can do thats slightly unorthodox is to write in typescript then ask chatGPT to rewrite your code in golang. You still have to maintain in golang but you get do the initial implementation part in typescript.
- Alifatisk 4y agoI don't think it's possible to run Ts in Golangs compiler. Have you considered rewriting your code to Go?
- patrickthebold 4y agoIt would be helpful to know what specific problems you have with the single threaded model. You might still have some options staying with node. I think you can have worker threads but maybe you can't share memory, or you might be able to run multiple node processes. Otherwise you probably want to just switch to go.
- techn00 4y agoWrite concurrent heavy tasks in Go. Write other tasks in typescript. Use https://connect.build https://connect.build to connect them.
- from 4y agoWhy are routine technical questions constantly appearing on HN? Ask on a specific subreddit Reddit or Stackoverflow.