Hacker News new | ask | show | jobs
by thisoneisreal 19 days ago
Can you explain more about how the front end aspect works? I'm not clear how the front end code could by TypeScript without a build step, unless I'm misreading.
1 comments

Node strips types on all imported code regardless of where that code executes.
Node doesn't run in the browser.
Presumably Node is the server (back end), and when the browser requests a TS file, Node is stripping the types before serving it to the browser.
That presumption is wrong, and doesn't quite make sense if you think about it.
Why doesn't it make sense? I actually do exactly this in my own setup, but with golang instead of Node.
I don't know what tooling you're using in go, but node does not do any kind of transformation to assets it serves over http. Running logic written in TypeScript on the front end requires some kind of bundler so that the browser can run the code.
I am aware and it’s not what I said.
You literally said "this even includes front-end code for the browser".

So what exactly are you referring to here?

I write all my application code in TypeScript, even if it is for the browser. I then import all that code into Node regardless of whether it will execute in Node. All code that will not execute in Node needs to be wrapped in a function for safety, because global references like "document" or "window" will not work in Node.
You write all your code in TS - great.

You run node with the TS support - great.

That doesn't explain how your front-end TS code is transformed into JS. You seem to be suggesting that node does it automatically, but it doesn't. The explanation of your setup isn't adding up.