Skip to content

Allow .ts extension when importing from a private mapping? #61613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
olalonde opened this issue Apr 25, 2025 · 4 comments
Closed
6 tasks done

Allow .ts extension when importing from a private mapping? #61613

olalonde opened this issue Apr 25, 2025 · 4 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@olalonde
Copy link

🔍 Search Terms

I'm using Node.js new typescript support and have the following in my package.json`:

  "imports": {
    "#root/*": "./src/*"
  },

In a file I'm doing the following import:

import type { QueryResolvers } from "#root/graphql/schema/types.generated.ts";

And I'm getting the following error:

This import uses a '.ts' extension to resolve to an input TypeScript file, but will not be rewritten during emit because it is not a relative path.ts(2877)

As far as I know, the above import will work so there is no need for that error. It would be nice to be able to disable it.

Here's my config:

{
  "compilerOptions": {
    // Base Taken from https://nodejs.org/docs/latest-v23.x/api/typescript.html#type-stripping
    "noEmit": true,
    "target": "esnext",
    "module": "nodenext",
    "rewriteRelativeImportExtensions": true,
    "erasableSyntaxOnly": true,
    "verbatimModuleSyntax": true,
    // custom:
    "strict": true,
    // https://stackoverflow.com/a/53957291
    "noErrorTruncation": true,
    "allowImportingTsExtensions": true
  }
}

✅ Viability Checklist

⭐ Suggestion

See above.

📃 Motivating Example

See above.

💻 Use Cases

See above.

@RyanCavanaugh
Copy link
Member

This isn't something we're going to support.

It's very bad for overall ecosystem build performance if transpiling requires touching the disk, so this check needs to be entirely syntactic, but this can't be syntactic because it's equally possible that your package.json said something like

  "imports": {
    "#root/*.ts": "./src/*.js"
  },

where rewriting this path would cause it to fail.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision labels Apr 25, 2025
@olalonde
Copy link
Author

olalonde commented Apr 26, 2025

I'm confused by your comment. I didn't ask anything about transpiling or rewriting a path. In fact, I'm not even transpiling at all - I'm using Node's new type stripping feature that allows it to run .ts files. I'm just asking about an option to disable the error notification when type checking. For now, I just added // @ts-ignore but it's kind of annoying having to repeat that all the time.

@RyanCavanaugh
Copy link
Member

If you're not transpiling, then turn off "rewriteRelativeImportExtensions": true, and you won't see this error

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Declined" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants