News for hackers. Stuff that matters.
Re:Modern Node.js Patterns by gabrielpoca118 on Sunday August 03, 2025 @04:02PM (#44779281)
Don’t forget the native typescript transpiler which reduces the complexity a lot for those using TS
Re:Modern Node.js Patterns by mmcnl on Sunday August 03, 2025 @04:23PM (#44779439)
Exactly. You don't even need --experimental-strip-types anymore.
Re:Modern Node.js Patterns by sroussey on Sunday August 03, 2025 @06:40PM (#44780450)
It strips TS, it does not transpile.

Things like TS enums will not work.

Re:Modern Node.js Patterns by throwitaway1123 on Sunday August 03, 2025 @08:43PM (#44781127)
In Node 22.7 and above you can enable features like enums and parameter properties with the --experimental-transform-types CLI option (not to be confused with the old --experimental-strip-types option).
Re:Modern Node.js Patterns by sroussey on Monday August 04, 2025 @03:27AM (#44782931)
Excellent update! Thanks!
Re:Modern Node.js Patterns by 9dev on Monday August 04, 2025 @05:29PM (#44791581)
Don’t use enums. They are problematic for a few reasons, but the ability to run TS code without enums without a build step should be more than enough of a reason to just use a const object instead.
Re:Modern Node.js Patterns by sroussey on Thursday August 07, 2025 @11:32AM (#44825805)
Oh, I agree.
Re:Modern Node.js Patterns by theThree on Sunday August 03, 2025 @07:06PM (#44780587)
It's still not ready for use. I don't care Enum. But you can not import local files without extensions. You can not define class properties in constructor.
Re:Modern Node.js Patterns by erikpukinskis on Sunday August 03, 2025 @07:36PM (#44780771)
Why would you want to do either of those?
Re:Modern Node.js Patterns by solarkraft on Sunday August 03, 2025 @08:44PM (#44781134)
Both are very common Typescript patterns.
Re:Modern Node.js Patterns by bapak on Sunday August 03, 2025 @11:33PM (#44781911)
Importing without extensions is not a TypeScript thing at all. Node introduced it at the beginning and then stopped when implementing ESM. Being strict is a feature.

What's true is that they "support TS" but require .ts extensions, which was never even allowed until Node added "TS support". That part is insane.

TS only ever accepted .js and officially rejected support for .ts appearing in imports. Then came Node and strong-armed them into it.

Re:Modern Node.js Patterns by silverwind on Monday August 04, 2025 @04:55AM (#44783380)
Maybe common in some legacy code bases. I recommend running with `erasableSyntaxOnly` for new code bases.
Re:Modern Node.js Patterns by throwitaway1123 on Sunday August 03, 2025 @09:03PM (#44781211)
Enums and parameter properties can be enabled with the --experimental-transform-types CLI option.

Not being able to import TypeScript files without including the ts extension is definitely annoying. The rewriteRelativeImportExtensions tsconfig option added in TS 5.7 made it much more bearable though. When you enable that option not only does the TS compiler stop complaining when you specify the '.ts' extension in import statements (just like the allowImportingTsExtensions option has always allowed), but it also rewrites the paths if you compile the files, so that the build artifacts have the correct js extension: https://www.typescriptlang.org/docs/handbook/release-notes/t...

Re:Modern Node.js Patterns by int_19h on Monday August 04, 2025 @02:15AM (#44782572)
Why not import files with extensions? That's the way JS (and TS) import is actually supposed to work.
Re:Modern Node.js Patterns by mcv on Monday August 04, 2025 @06:10AM (#44783858)
I have to admit I was a bit surprised when I was suddenly expected to get rid of all extensions in import. Sure, looks clean, but is it right?