Skip to content

Destructuring re-exports using type from symlinked node-modules results in relative paths used in import() type #1347

@AlCalzone

Description

@AlCalzone

Feels like I'm hitting all the edge cases. This can be reproduced using the following test case:

// @Filename: /packages/b/package.json
{
  "name": "package-b",
  "type": "module",
  "exports": {
    ".": "./index.js"
  }
}

// @Filename: /packages/b/index.js
export {};

// @Filename: /packages/b/index.d.ts
export interface B {
	b: "b";
}

// @Filename: /packages/a/package.json
{
  "name": "package-a",
  "type": "module",
  "imports": {
    "#re_export": "./src/re_export.ts"
  },
  "exports": {
    ".": "./dist/index.js"
  }
}


// @Filename: /packages/a/tsconfig.json
{
  "compilerOptions": {
    "module": "nodenext",
    "outDir": "dist",
    "rootDir": "src",
    "declaration": true,
  },
  "include": ["src/**/*.ts"]
}

// @Filename: /packages/a/src/re_export.ts
import type { B } from "package-b";
declare function foo(): Promise<B>
export const re = { foo };

// @Filename: /packages/a/src/index.ts
import { re } from "#re_export";
const { foo } = re;
export { foo };

// @link: /packages/b -> /packages/a/node_modules/package-b

The relevant part are the type declarations generated for package-a:

//// [re_export.d.ts]
import type { B } from "package-b";
declare function foo(): Promise<B>;
export declare const re: {
    foo: typeof foo;
};
export {};
//// [index.d.ts]
declare const foo: () => Promise<import("../../b/index.js").B>;
export { foo };

I would have expected the following declaration:

declare const foo: () => Promise<import("package-b").B>;
export { foo };

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions