Skip to content
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

IsolatedDeclaration: support rewriteImportExtension option #9838

Open
Dunqing opened this issue Mar 18, 2025 · 0 comments
Open

IsolatedDeclaration: support rewriteImportExtension option #9838

Dunqing opened this issue Mar 18, 2025 · 0 comments
Assignees
Labels
A-isolated-declarations Isolated Declarations E-Help Wanted Experience level - For the experienced collaborators

Comments

@Dunqing
Copy link
Member

Dunqing commented Mar 18, 2025

The rewriteImportExtensions option now works as configured/desired for source files; however, it doesnt apply to the generated declarations file.

Input

// src/example.ts
import { Provider, type MODEL } from './model.ts';

export async function foobar(): string { ... }

Output: rewriteImportExtensions: 'rewrite'

// out/example.js ✅
import { Provider } from './model.js';

export async function foobar() {
  // ...
}

// out/example.d.ts ❌
import type { MODEL } from "./model.ts"; // <<< path does not exist

export declare function foobar(): string;
export {};

Output: rewriteImportExtensions: 'remove'

// out/example.js ✅
import { Provider } from './model';

export async function foobar() {
  // ...
}

// out/example.d.ts ❌
import type { MODEL } from "./model.ts"; // <<< path does not exist

export declare function foobar(): string;
export {};

In both scenarios, the example.d.ts file's import paths are unchanged. This is/will always be invalid since the source .ts file will not exist post-transform.

While the generated d.ts content does match tsc output, it only works when the dts is placed as sibling files to the source ts files. And for a npm context, the source *.ts files would have to be published alongside the *.d.ts files to work, which honestly makes the *.d.ts files redundant/irrelevant, since all types/enums/func definitions are repeated.

Actually, this could create scenarios where more complex generics are broken because two copies of the complex type are loaded (1 from .ts and 1 from d.ts) and are sufficiently complex that tsc treats them as separate types, breaking narrowing, inference, etc.

Originally posted by @lukeed in #5395

@Dunqing Dunqing added the A-isolated-declarations Isolated Declarations label Mar 18, 2025
@Dunqing Dunqing added the E-Help Wanted Experience level - For the experienced collaborators label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-isolated-declarations Isolated Declarations E-Help Wanted Experience level - For the experienced collaborators
Projects
None yet
Development

No branches or pull requests

1 participant