Hacker News new | ask | show | jobs
by tbrock 1684 days ago
We recently went through this hell converting a NodeJS codebase to TypeScript. One reason many people willingly enter this hellscape is because we need ES modules for typescript.

I say “need” because Typescript wont ingest types from “required” files, you have to import them as modules.

So before we converted a single file to TS we has to audit all commonjs imports and exports to convert them to ES modules.

I agree wholeheartedly that the end result was a fools errand. I would have rather spent the time adding support for importing types via a require which for some reason returns any “any” today.

2 comments

I think you've confused Typescript's own import/export system with ESM. It uses the `import` syntax, but it's not ESM internally, it's its own thing designed to ingest and export to multiple module types.
The incompatibility is indeed exponentiated with TypeScript.

There is currently no non-hacky way for using both legacy modules and ES Modules in the same project, and many libraries on NPM have moved to ESM-only. TypeScript's transpilation needs to know what to target as regards modules and JS version, which makes things even crazier than they already are.