Hacker News new | ask | show | jobs
by austin-cheney 20 days ago
I write in vanilla TypeScript. I do not have any build step in my application. Since Node now supports native type stripping I don't have a compile step either. I just write my code and then point node at the main file, and this even includes front-end code for the browser.
1 comments

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.
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 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.