5 ms·
Don’t forget the native typescript transpiler which reduces the complexity a lot for those using TS
by gabrielpoca118 1y ago
Don’t forget the native typescript transpiler which reduces the complexity a lot for those using TS
- mmcnl 1y agoExactly. You don't even need --experimental-strip-types anymore.
- sroussey 1y agoIt strips TS, it does not transpile. Things like TS enums will not work.
- throwitaway1123 1y agoIn 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).
- sroussey 1y agoExcellent update! Thanks!
- 9dev 1y agoDon’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.
- sroussey 1y agoOh, I agree.
- theThree 1y agoIt'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.
- erikpukinskis 1y agoWhy would you want to do either of those?
- solarkraft 1y agoBoth are very common Typescript patterns.
- bapak 1y agoImporting 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.
- silverwind 1y agoMaybe common in some legacy code bases. I recommend running with `erasableSyntaxOnly` for new code bases.
- throwitaway1123 1y agoEnums 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/typescript-5-7.html#path-rewriting-for-relative-paths https://www.typescriptlang.org/docs/handbook/release-notes/t...
- int_19h 1y agoWhy not import files with extensions? That's the way JS (and TS) import is actually supposed to work.