tsconfig icon indicating copy to clipboard operation
tsconfig copied to clipboard

Consider `allowImportingTsExtensions`

Open fregante opened this issue 1 year ago • 3 comments

https://www.typescriptlang.org/tsconfig/#allowImportingTsExtensions

Required for:

import {addTests} from './collector.ts';

Which is required by node --experimental-strip-types

This is unrelated/unaffected by #29

I don't know what are the consequences of allowing .ts imports though. Also XO currently enforces .js extensions:

require file extension '.js'. (n/file-extension-in-import) XO

fregante avatar Aug 21 '24 09:08 fregante

Enabling allowImportingTsExtensions means that it's easy for users to make the mistake of using .ts instead of .js. I think this will cause a lot of problems. I'm not sure it makes sense to introduce this pitfall just to enable the user of a highly experimental Node.js feature. It seems like for now, you should just manually enable that in the projects tsconfig. In addition, it's also unclear whether it has any other hidden gotchas.

sindresorhus avatar Aug 21 '24 09:08 sindresorhus

experimental Node.js feature

Yeah we'll definitely have to wait and see if it's worth it.

whether it has any other hidden gotchas

It is a tricky situation.

  • Node has to look for the .ts file because it's reading a .ts file source;
  • packages have to look for a .js file because they have .js entry points.

My guess is that allowImportingTsExtensions exclusively makes sense for projects/applications, and not for modules that are meant to be distributed.

I think Node is the only tool that requires this, and it's experimental.

fregante avatar Aug 21 '24 10:08 fregante

Type stripping is no longer experimental and it's enabled by default in node since 22.18. Example:

  • https://github.com/nodejs/node/issues/59364

fregante avatar Aug 08 '25 17:08 fregante