News for hackers. Stuff that matters.
Re:TypeScript enums: use cases and alternatives by madeofpalk on Monday January 20, 2025 @07:07AM (#42767840)
> in a future where TypeScript code can be run with Node.js

FYI, this is now. Node 23.6 will just run typescript files than can have their types stripped https://nodejs.org/en/blog/release/v23.6.0#unflagging---expe....

There is a seperate --experimental-transform-types flag which'll also transform for enums, but no idea if they ever intend to make this not experimental or unflagged.

Re:TypeScript enums: use cases and alternatives by plopz on Monday January 20, 2025 @07:14AM (#42767900)
I think the biggest hurdle in getting something like that to work is how typescript handles the import syntax
Re:TypeScript enums: use cases and alternatives by madeofpalk on Monday January 20, 2025 @09:43AM (#42769213)
you just tell typescript to stay away from import syntax, and use node-native resolution and it all just works.

its 2025 and node is finally good :)

Re:TypeScript enums: use cases and alternatives by dunham on Monday January 20, 2025 @12:18PM (#42770817)
It would be nice if node did tail call optimization, but that seems unlikely at this point (v8 added and then removed it). I've been using bun as a backend for my toy language because of this.
Re:TypeScript enums: use cases and alternatives by WorldMaker on Monday January 20, 2025 @12:06PM (#42770673)
Most of the "drama" in recent Typescript, such as requiring file extensions, with the import syntax has been aligning with the Browser/Node requirements. If you set the output format to a recent enough ESM and the target platform to a recent enough ES standard or Node version it will be a little more annoying about file extensions, but the benefit is that it import syntax will just work in the browser or in Node.

The only other twist to import syntax is marking type-only imports with the type keyword so that those imports can be completely ignored by simple type removers like Node's. You can turn that check on today in Typescript's compile options with the verbatimModuleSyntax [1] flag, or various eslint rules.

[1] https://www.typescriptlang.org/tsconfig/#verbatimModuleSynta...