Open fregante opened 1 month ago
What's the benefit for ESM-only projects? Not sure I see the value in it.
I think the benefit is to stop fighting TypeScript with imports: just let the user use what they write. Specific rules/preferences can be enforced via eslint.
Or at least that’s the promise
There is really no fighting if you are pure ESM. And I don't really see the point in allowing require
here and then use a linter to disallow it, when it can just be disallowed here instead.
There is really no fighting if you are pure ESM
I reached this point because this config blocks import attributes AKA “pure ESM”, so the fight still exists. Then node wants .ts imports and TS wants .js imports. The fight continues.
If preserve
keeps its promise to just allow modules as written, I think it’s advantageous.
This is what I see with @sindresorhus/tsconfig
6, without changes: ESM is not allowed, require
is:
If preserve keeps its promise to just allow modules as written, I think it’s advantageous.
I suggest trying it out in practice first on some popular projects to see its effects. I'm already lukewarm to it, but I'm definitely not adding it here until it's proven to work.
This is what I see with @sindresorhus/tsconfig 6, without changes: ESM is not allowed, require is:
That's just the fact of using TS in general. Every JS feature has to be supported by TS before you can use it there. I thought TS already supported import attributes: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html
I thought TS already supported import attributes
They do, but you have to use a specific config (and this config particularly blocks resolveJsonModule
because Node <18.20 doesn't support it)
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-4.html#support-for-require-calls-in---moduleresolution-bundler-and---module-preserve
I think this is the right config to finally get TS out of the way
More info in https://github.com/microsoft/TypeScript/pull/56785