Live data from Hacker News

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

nodejs.org

51–60 of 275 posts

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

#51
post #43

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.

> (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?

And for a few earlier versions `type: module` in package.json was all that was needed for .js files to be treated as ESM.

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

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

Typescript mission is to strip itself of typing, what’s your point? Typescript will never be Java, you’ll never have runtime reflection.

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

#53
post #34
post #17

Earlier quoted context omitted.

TypeScript never promised improving safety, maybe it’s a common misconception. But TypeScript has no runtime mode or information. You were always at the mercy of running and not ignoring the typechecker. Nothing stopped you from running ts-node or tsx on code with egregious type errors. TypeScript is more like a linter in that regard.

> TypeScript is more like a linter that's exactly the point--GP is pointing out that node can't do that part

Which is why the title is "Node can now execute Typescript files" and not lint, check, or even run TypeScript files.

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

#54
post #20
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.

One of Typescript's design goals is that removing all type-related parts of the source text should yield a valid JavaScript file. A typescript compiler does not generate code (unlike, say, PureScript). You can run a typechecker (such as tsc) that check various properties of your code statically, relying on the type information. It is then erased. The same applies, say, to Python: type annotations are ignored at runti…

> Somehow similarly, Java's type information is also partly erased in the bytecode;

Just for generics, I believe

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

#55

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.

does it have a go fmt / lint command yet?

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

#56
post #20
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.

One of Typescript's design goals is that removing all type-related parts of the source text should yield a valid JavaScript file. A typescript compiler does not generate code (unlike, say, PureScript). You can run a typechecker (such as tsc) that check various properties of your code statically, relying on the type information. It is then erased. The same applies, say, to Python: type annotations are ignored at runti…

Except in Python you can easily access the type hints at runtime, which allowed people to build ergonomic libraries such as Pydantic

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

#57

Earlier quoted context omitted.

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.

does it have a go fmt / lint command yet?

Nope

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

#60
post #3
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.

Exactly! Type checking can be long and costly.

Ocaml does it fast
Post reply on HN