Live data from Hacker News

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

nodejs.org

191–200 of 275 posts

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

#191
post #46

Earlier quoted context omitted.

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

Except it doesn't. In anything serious, you have to wait for a full type check to happen before you run your TS code. Why would you run code that has not been checked yet and could throw very weird errors like undefined property access? That just doesn't make sense. Yes, you can wait for your editor in your current open file, if you are lucky and the change in the open file doesn't break anything downstream in anothe…

This is not my experience at all. In my experience, it's often quite useful being able to run code that doesn't fully type-check, as long as I do make sure everything's correct by the time I commit it. For example, I might be refactoring a module with some tests, and make a change that breaks the tests and some code in some other module. At this point, I often go in this order:

1. See that the tests aren't type checking correctly (usually for an obvious reason like adding an extra parameter or something). 2. Fix the tests using the type hints. 3. Run the tests to make sure my refactoring made sense and didn't break anything unexpected at runtime. 4. Fix all the uses in other modules.

Step 3 requires me to be able to run code that doesn't type-check correctly, and that's a useful feature.

There's also similar cases where I want to see how something looks in the UI even if it's not properly hooked up yet and causing type errors - I can check that part of the UI works and that it throws the correct runtime error (equivalent to whatever error typescript has). I've also had cases where I've cast things to `unknown` because I don't want to figure out the type just yet, and then written an implementation that is filled with typescript errors but will work at runtime as a mini proof of concept, only to later go back and get the types right.

I shall think you're underestimating how important fast cycle times are. When I'm developing, I normally have my linter, tsc, the dev server (tsx or vite), and the test runner all running simultaneously in watch mode. At any one point, I'm probably only interested in the output from one of these tools (the type checker until the types are all correct, then maybe the test runner until everything's green there). But if I run all of them at once, then they all run optimistically, and the tool I'm interested in is more likely to give me immediate feedback. That's really useful! Even with the new 10x typescript compiler, I'd still rather my tests start running immediately rather than waiting for another process to start and finish before they get going.

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

#192

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.

I can’t help but think that none of these would have happened without Deno doing it first. It was basically the pragmatic Node before Node started to get reasonable.

That's kind of the whole history of NodeJS, dragged-forward kicking and screaming right from the 0.x and IO days!

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

#193

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.

Watching NodeJS fill in these gaps the last 5 years or so has been great, I strongly prefer using built-in stuff as much as possible now to avoid bloating the modules and becoming dependent on a thousand random people being good-stewards of their packages.

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

#194
post #182
post #65

Earlier quoted context omitted.

npx prettier

I moved on to Biome (which replaces both ESLint and Prettier) and while the IDE extensions have been a bit buggy, it's much faster and has fewer dependencies. It was always a pain to set up ESLint + Prettier.

Replacing something hard to setup with something buggy is a win?

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

#195
post #182
post #65

Earlier quoted context omitted.

npx prettier

I moved on to Biome (which replaces both ESLint and Prettier) and while the IDE extensions have been a bit buggy, it's much faster and has fewer dependencies. It was always a pain to set up ESLint + Prettier.

ESLint these days doesn't have any styling related lints (unless you opt into them) which means that it works out-of-the-box with Prettier (or Biome's formatter, presumably).

My fear with Biome is missing out on type-aware lints, but I know Oxlint has had some success integrating the new Go typescript compiler, so maybe that will work out for Biome as well.

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

#196
post #162
post #92

Earlier quoted context omitted.

For one I do not want to run my startup at the mercy of VC funded tech. Node.js is open source and maintained by a foundation, it will not "run out of funds" or be abandoned if there is no profitability in the near future.

Yeah, but it's not a big bet. Deno can do it, Bun can do it, if they die a tragic VC-fueled death then somebody else (maybe Node) can do it. Using Bun to me is just like using a microwave oven in 1980 — there weren't a lot of microwavable convenience foods yet, but you could sure heat up some leftovers more conveniently and quickly.

comparing bun to oven is one of the most clever things that I have seen.

My mind is actually so impressed right now in the sense that bun is well owned by oven.sh company and what you said makes sense...

Do I make sense? Seriously, I can't explain but feel a little mind blown by what you wrote.

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

#197
It also exposes a function which does type stripping (as `import { stripTypeScriptTypes } from 'node:module'`).

This lets you build simple web apps (i.e., those with no frontend dependencies) as pure TypeScript, including the frontend, by stripping the types out from your frontend scripts as you serve them: https://github.com/bakkot/buildless-ts-webapp

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

#198
post #187
post #77

Earlier quoted context omitted.

Agreed about TS, but Python type annotations are not ignored. They are executed as code (all type annotations are valid expressions) and the results are stored on the module/class/function object that contains the annotated variable

Python type annotations get turned into metadata which other tools may inspect at runtime, but the Python runtime itself does nothing with it. It's just well-structured comments. In Python basically everything is executable, and so are type annotations.

Somewhat related: you technically can access some type metadata in TypeScript at runtime using the `emitDecoratorMetadata` and `experimentalDecorators` tsconfig options, along with Microsoft's `reflect-metadata` polyfill package. There was a trend at one point where people were writing database ORMs using decorator metadata (e.g. Typegoose, TypeORM, and MikroORM).

This of course requires your build tool to actually understand the TS type system, which is why it's not supported in tools like esbuild and tsx (which uses esbuild under the hood).

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

#199
post #182

Earlier quoted context omitted.

I moved on to Biome (which replaces both ESLint and Prettier) and while the IDE extensions have been a bit buggy, it's much faster and has fewer dependencies. It was always a pain to set up ESLint + Prettier.

Replacing something hard to setup with something buggy is a win?

They've improved, and they will be fine pretty soon.

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

#200

Earlier quoted context omitted.

Not needing a separate compile step just to run some script sounds great to me. I will run tsc if I want a type check.

There is always a compile step (JS -> Bytecode -> Machine code). The question is only if it is visible to you or not. They could have made it totally transparent to you by fully support TS including type checking under the hood including support full TS and not this subset of it, but decided not to do so. There is nothing inherently great to have less compile steps if you are not even aware of it. See v8 how many com…

The point is I don't have to deal with the index.js blob that gets produced by running the compile step myself. Worse yet the source maps. It's significantly less steps so pretty helpful I'd say.
Post reply on HN