Run TypeScript code without worrying about configuration

tsx.is

97 points by nailer a day ago


jauco - a day ago

Newer versions of node can run typescript directly[1]. The one where types are simply stripped is considered stable[2] (but you can’t use syntax that node doesn’t understand, such as enums).

They’re working on making features work that require some transpilation as well

[1]: https://nodejs.org/en/learn/typescript/run-natively [2]: https://github.com/nodejs/node/pull/58643

chmod775 - a day ago

That's some terrible naming. Now there's two things "tsx" stands for in the TypeScript ecosystem.

low_tech_punk - a day ago

To make matters worse, there is actually a third thing named "TSX" gaining traction right now:

https://esm.sh/#tsx

low_tech_punk - a day ago

I don't think it's accurate to say "without worrying about configuration". The next line is more accurate:

> tsx runs your TypeScript code with modern and sensible defaults, making it user-friendly and especially great for beginners.

You'd still have to worry about config if you want to make adjustment and when that happens, the implicit smart defaults become a friction point.

It might also surprise you with errors when you attempt to bundle the code. It'd be nice to have tsx available at runtime so I can run TypeScript code without worrying about the transpiler

kylecordes - 15 hours ago

A challenge with TSX, and as I understand other similar tools, is that it doesn't support TypeScript decorator metadata. A few years ago, libraries using that started to get popular, so many older projects have a significant obstacle to moving away from running the TypeScript compiler JS output.

Starting a new project today, I think the right move is to use TSX or Bun or whatever. You want a roadblock at the very first moment you start trying one of these limited compatibility libraries, Because it won't work and then you'll pick a different library that doesn't rely on non-erasable TypeScript syntax.

dimgl - a day ago

tsx is such an amazing tool. A couple of years ago I discovered it and abandoned ts-node and all of the alternatives. I still use it today and I was a sponsor for many months.

Thanks again to the author. It has saved me (and my team) dozens of hours. And I was able to replace all of my ESBuild workarounds that I had made to easily run TypeScript. Cheers.

stevage - 16 hours ago

I generally use Bun for this purpose. I don't really know how Bun does what it does, but it seems to manage to do Node-ish things like NPM and running Typescript without getting caught up in all the myriad variations of TS and ESM configuration options. Just works.

hu3 - a day ago

I was curious about how it works.

It seems to be a wrapper for esbuild that transpiles typescript then calls your local node (it doesn't bundle nodejs).

From https://tsx.is/faq :

"tsx: Uses esbuild for fast compilation and does not perform type checking."

From https://tsx.is/node-enhancement :

"Under the hood, tsx calls node. This means the Node.js features supported in tsx depend on the Node.js version you have installed."

cellis - a day ago

It really is the worst name, unsearchable and so overloaded. But it's been an awesome tool. I hope they rename it.

fjcero - a day ago

Use bun

postalrat - a day ago

The JavaScript version can be called jsx.

dzonga - 20 hours ago

till present day, I haven't found a justified reason of why people use typescript on the backend.

C# - gives you similar syntax with a better ecosystem + tools. if it's just types you love Java, Kotlin, Golang the same. Better languages better tools, better ecosystems.

typescript on the backend shows people have more money than sense.

maybe after all i'm lost on the incentives.

lacoolj - a day ago

lol the timing of these two posts (this and https://news.ycombinator.com/item?id=44597966) feel deliberate

__alexs - 21 hours ago

We've been using ts-node with swc for ages and seems to work great. Never really understood why tsx exists.

molszanski - a day ago

I love tsx. Lately I’ve been also using bun for the same purpose.

spankalee - a day ago

Does this just pass the --experimental-strip-types flag to node?

gosukiwi - a day ago

TypeScript is great, the only bad thing is that it can be a pain to get the configuration right

90s_dev - a day ago

Note that you can also get TSX in native Node.js with minimal configuration[0]. This is accomplished via module hooks and TypeScript's own compiler (or bring your own compiler like swc).

[0]: https://github.com/sdegutis/immaculata

bravesoul2 - a day ago

tsx vs. ts-node?

monarchwadia - a day ago

I do love tsx.

neeelrusia - a day ago

[dead]