Live data from Hacker News

Node.js is able to execute TypeScript files without additional configuration

nodejs.org

41–50 of 275 posts

Re: Node.js is able to execute TypeScript files without additional configuration

#41

Earlier quoted context omitted.

What are the recent improvements in node itself? Last actually note-worthy improvement I heard of was properly supporting import/export (although do you still need to use the .mjs hack?), but I've been out of the loop here for sometime so would be nice to know what they've added since.

using, memory64, undici, async local storage, ESM import improvements, type stripping, local storage / session storage, env file support, built in file watching. Those are just the ones I mainly remember. There is a lot more.

Adding to the list: permissions, CLI styling/colouring, require(esm), globs, test runner.

Re: Node.js is able to execute TypeScript files without additional configuration

#42
post #29

Earlier quoted context omitted.

> A typescript compiler does not generate code Except for where it does: Enums, namespaces, parameter properties, etc.

Just use erasableSyntaxOnly = true and you're fine.

Hadn't heard of that. Thanks

Re: Node.js is able to execute TypeScript files without additional configuration

#43
post #4

Impressed with what Node is doing the last years, deno and bun has really made Node focus and improve. It was stuck for a while

What are the recent improvements in node itself? Last actually note-worthy improvement I heard of was properly supporting import/export (although do you still need to use the .mjs hack?), but I've been out of the loop here for sometime so would be nice to know what they've added since.

> (although do you still need to use the .mjs hack?)

Syntax detection is enabled by default in v22.7.0, v20.19.0:

https://nodejs.org/api/packages.html#syntax-detection

Sounds like the obvious correct solution, making .cjs and .mjs obsolete - unless of course someone uses import() statements exclusively, in which case I need to ask: why?

Re: Node.js is able to execute TypeScript files without additional configuration

#44
post #37
post #29

Earlier quoted context omitted.

> A typescript compiler does not generate code Except for where it does: Enums, namespaces, parameter properties, etc.

This is true but these are also old features, and the TS team have stated that they will not add any more features like those, and to a certain extent regret adding them initially (particularly decorators, which iirc were added because the Angular framework wanted to use them). You can also see that these features aren't really being updated to match recent Typescript developments (parameter properties can't do true…

> I find it's useful when my typescript source matches the generated Javascript code as much as possible.

Is this that worth? In the past I was able to read past async/await desugaring generated by TypeScript, and there are several useful non-JS syntaxes that are much easier to read than that (e.g. enums). Of course it would be great if ECMAScript eventually adopts them, but that doesn't seem like a strict requirement for me.

Re: Node.js is able to execute TypeScript files without additional configuration

#45
I think this + node:test makes Node.js a pretty compelling sensible default for most things now. Running things with `tsx` was such a QoL improvement when it happened, but it didn't solve everything.

Runtime type assertion at the edges is mostly solved through `zod` and tools like `ts-rest` and `trpc` makes it so much easier to do full-stack Typescript these days.

Re: Node.js is able to execute TypeScript files without additional configuration

#46
post #2

It looks like this works by stripping away the type information, so at best it saves you a transpilation pass and doesn't improve safety.

>so at best it saves you a transpilation pass and doesn't improve safety.

That's a bit misleading. Node being able to run TS code does not "improve safety", because that's not where the type checking happens. You can do type checking in your editor, or various other points in your toolchain.

Node being able to run TS code reduces the friction in writing TS code, which indirectly helps with type safety.

Re: Node.js is able to execute TypeScript files without additional configuration

#47

Is there any movement in the node world for the runtime to be able to ascertain types? Obviously nodejs doesn't do this, but does Bun or Deno or are there plans for any of this in the future?

i don’t think you’ll see this at the typescript level, and you won’t see anything like this that compiles to javascript. specifically, compiling typescript to javascript with runtime checks would not actually be very useful.

typescript is pretty ambiguous about a lot of the things that would need explicit definition for runtime safety, and anyways we already have tools for that - it’s called zod.

and comprehensive checks would incur a significant runtime penalty, unless they were restricted to external interfaces, which is what you’re really concerned about. we already have tools for that - protobuf, swagger, etc.

anything else is sharing a runtime with you. so either it’s in your ide, and you just don’t write shitty code; or you’re trapped in some kind of demonic javascript prisoner’s dilemma, and you are mutable.

so typescript is basically ‘good enough’ for developers.

thinking forward anyway, and assuming you’re really willing to share a runtime with a stranger…

node doesn’t really operate in that kind of context, but maybe browser code does. i could imagine a framework based on web components, workers, and maybe iframes, taking advantage of message boundaries to enhance analysis and conceal code generation. it’s not that much better than typescript.

but if you want efficient runtime checks, and you want to leverage static analysis and strong module boundaries to scope the type-checking codegen, and you probably need additional syntax, you might as well target wasm.

Re: Node.js is able to execute TypeScript files without additional configuration

#48
post #36

Great, it does type stripping by replacing TypeScript with whitespace. Can it also now load ES5 modules? That way we can use them for everything.

> Can it also now load ES5 modules?

ES5 standard (released in 2009) didn't have modules.

Re: Node.js is able to execute TypeScript files without additional configuration

#50

I think this + node:test makes Node.js a pretty compelling sensible default for most things now. Running things with `tsx` was such a QoL improvement when it happened, but it didn't solve everything. Runtime type assertion at the edges is mostly solved through `zod` and tools like `ts-rest` and `trpc` makes it so much easier to do full-stack Typescript these days.

This. It's 2025 and the node ecosystem is finally usable by default!

ESM modules just work with both Node and Typescript, Node can run .ts files, and there's the a good enough test runner built in. --watch. The better built in packages - `node:fs/promises` - are nice with top-level await for easier async loops.

It took a while to convince everyone involved to just be pragmatic, but it's nice now.

Post reply on HN