4 ms·
Running TypeScript Natively in Node.js
- gabrielsroka 1y agoSee also from 6 months ago https://news.ycombinator.com/item?id=42630790 https://news.ycombinator.com/item?id=42630790
- jadbox 1y agoThis is great to finally see get added. I wonder why they decided to build their own type stripper instead of just bundling tsc/swc. It feels like Node.js is going to be plagued with bugs whenever TypeScript adds new type constructs, which may take months to get patched.
- Eric_WVGG 1y agoWould it be possible for the maintainers of Typescript to provide an official stripper that could be deployed alongside new versions of Typescript, and then snapped in?
- yladiz 1y agoI'm not certain but I would be surprised if the TS and Node devs didn't discuss the functionality that's in Node now, since TS must have some definition of what an erasable type is (or rather, what few features aren't erasable, like enums), since the corresponding --erasableSyntaxOnly flag in TS was probably made specifically because of Node.
- mosdl 1y agoIts just stripping types, so new constructs should not matter - there is no parsing.
- eyelidlessness 1y agoIt uses swc under the hood.
- Normal_gaussian 1y agoWhilst I use an esbuild based build pipeline to produce production artifacts, I've found that the combination of native type transformation and node:test improvements is now sufficient to do away with most test frameworks. My nodejs projects have tests that run faster and have fewer breaking dependencies. The two things I have to do are to always annotate type imports with type (I have a script for that), and to use file extensions on imports.
- dimava 1y agoThere's an ESLint rule with autofixes for that (annotating type imports) One for extension should exist somewhere too
- steve_adams_86 1y agoI don't mean this rhetorically, but what are the benefits of using node over something like deno now? It has been so long since I lived in the node ecosystem. I imagine it has gotten quite a bit better. Is the main benefit just ecosystem/compatibility stuff? Deno sometimes has some odd compatibility issues, but not often. The low-overhead, sane defaults, just-build kind of nature of it has become very appealing to me. Being able to build CLIs in portable binaries using a language my coworkers understand is really nice (despite that they're like 60mb, haha). I prefer Go personally, but ultimately prefer being able to collaborate.
- reactordev 1y agoIt’s purely ecosystem at this point. Deno, Bun, any runtime is more modern. It’s nice they are catching up but by the time typescript is a native citizen in node, others may take the crown. The codebase is ooof. That said, there’s something to be said about being the first mover and having the ecosystem so node isn’t going away anytime soon, nor is the npm/npx ecosystem. Go has the ability to, with a goja fork [1], to execute ESM but you would still need to transpile using another go tool to run it. I have such a runtime but it’s nowhere near as fast as bun or deno. I use it mainly so I can have agents do my local bidding. [1] https://github.com/grafana/sobek https://github.com/grafana/sobek
- leptons 1y ago>It’s purely ecosystem at this point. Definitely not just about ecosystem. When AWS Lambda supports Deno, then maybe someday further down the line, I might think about trying it once for something unimportant. If that goes well, then we'll see.
- reactordev 1y agoAWS Lambda supports custom runtimes so you can roll your own. All you need is a container. https://gist.github.com/begoon/993e29f5cf9a384b9e0e96e70a71b491#Dockefile-deno https://gist.github.com/begoon/993e29f5cf9a384b9e0e96e70a71b... But for ts/js land, lambda is node unless you want to build your own containers.
- ChrisArchitect 1y agoNews from January https://nodejs.org/en/blog/release/v23.6.0 https://nodejs.org/en/blog/release/v23.6.0
- russellbeattie 1y agoI honestly wish Microsoft and TypeScript enthusiasts would transform it into an official standalone language and stop polluting the JavaScript ecosystem. Like C++, it could be a true superset of JS, importing JS code freely into TypeScript projects. It would also allow TypeScript to do whatever it wanted and not have to worry about transpilation. If it needs to work in the browser, it can be bundled into web assembly.
- wrs 1y agoThis is a mischaracterization of TypeScript. Unlike the relationship of C++ to C, TS is explicitly not a separate language from JS, and introduces no new capabilities. There’s no engine that executes TypeScript. It doesn’t do anything (*) that JavaScript doesn’t do. It just layers a type system onto JavaScript so you can tell when your JS code doesn’t make sense. (*) with small exceptions like enums, which some think were a mistake for that reason
- winrid 1y agoYeah but it could be, as the runtime could take advantage of the type defs.
- wrs 1y agoSo much of the TS type system is just there to capture all the weird things you can do in JS. If you just wanted a new strongly typed dynamic language, I don't think TS is what you'd come up with. It is designed for a very large, but unique, niche domain, and that domain already has some incredibly optimized runtimes.
- winrid 1y agoI wouldn't come up with a new language. I would use TS and use the types to optimize runtime decisions like using numbers to index arrays, without having to carry extra info about the number, and so on. I would change nothing except the runtime. Are you somehow arguing that's bad?
- vivzkestrel 1y agoWake me up when it gets as good as running tsx aka support for path aliases in dev and test environments and support for watch mode
- butz 1y agoDoes this mean we can finally drop `typescript` dependency from build chain?
- yencabulator 1y agoSo if you use this, what do you use to enforce the types? Are you still running tsc --noEmit? I'm embarking on a project where the various tsconfig files are getting quite unwieldy. I'd have already jumped to Deno but it just won't work right when the actual deployment is to Cloudflare Workers.