Repository: TypeScript
Issue: Change declaration file import paths from `.js` to `.d.ts`
Labels: Suggestion,Awaiting More Feedback,Domain: Declaration Emit

# Suggestion

<!--
  Please fill in each section completely. Thank you!
-->

## 🔍 Search Terms

<!--
  💡 Did you know? TypeScript has over 2,000 open suggestions!
  🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.
  The "Common Feature Requests" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests

  Replace the text below:
-->

- `declaration import paths`
- `esnext declaration import path`

I also know there's a lot of somewhat-related conversation around this area in #37582 and #46452 , but this is only for the output of declaration files, so I'm not sure if it's exactly related to those issues or not. If it is, feel free to close this and accept my apologies. 

## ✅ Viability Checklist

<!--
   Suggestions that don't meet all these criteria are very, very unlikely to be accepted.
   We always recommend reviewing the TypeScript design goals before investing time writing
   a proposal for ideas outside the scope of the project.
-->
My suggestion meets these guidelines:

* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [x] This wouldn't change the runtime behavior of existing JavaScript code
* [x] This could be implemented without emitting different JS based on the types of the expressions
* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).


## ⭐ Suggestion

When using TypeScript to `emitDeclarationOnly`, it outputs a `.d.ts` file. However, the contents of that file keep the same import path. An example:

```ts
// in `index.d.ts`
export {TestFunc} from './other.js';
```

What would be nice, however, is to have the declaration file import paths point to the actual file, like so:

```ts
// in `index.d.ts`
export {TestFunc} from './other.d.ts';
```

To maybe help see more clearly, I created [this repo](https://github.com/frehner/typescript-output-testing) that has the current source code and output files when running `npx tsc --emitDeclarationOnly`. You'll note that the [`/types/index.d.ts`](https://github.com/frehner/typescript-output-testing/blob/main/types/index.d.ts) file has an import/export path to a file that doesn't actually exist, but is still found when using something like node's resolution algorithm.

## 📃 Motivating Example

When using Deno, you can put up your library + types up on a CDN. However, Deno must have the exact path to the file in order for it to work. Unfortunately it seems that it means that the other declaration files cannot be found because the import path in the declaration file isn't exactly correct. 

Unless I've missed something important about TS / Deno? 

## 💻 Use Cases

I don't _think_ this would have any effects on the ecosystem, would it? Is there a chance it would maybe even make things slightly faster when looking up types (even for node projects), because the declaration files are pointing directly to the correct file instead of having to go through the resolution algorithm? I'm not sure, I'll defer to you experts. 

Thank you ❤️