Microsoft/TypeScript

Module names in declaration files mismatch with keys in dependencies

Open

#50,917 建立於 2022年9月23日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: Declaration EmitHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

Bug Report

🔎 Search Terms

  • declaration files
  • module names
  • dependencies
  • moduleResolution
  • nodenext

🕗 Version & Regression Information

  • Typescript version: v4.8.3

💻 Code

File structure:

├── package1
│   ├── index.d.ts
│   └── package.json
└── package2
    ├── baz.ts
    ├── index.ts
    └── package.json

TS files:

// package1/index.d.ts
export interface FOO {}

// package2/baz.ts
export const BAZ = {
  foo: {} as Partial<import("pkg1").FOO>,
};

// package2/index.ts
import * as baz from "./baz";
export const BAZ = baz.BAZ;

Generated declaration files:

// package2/dist/baz.d.ts
export declare const BAZ: {
  foo: Partial<import("pkg1").FOO>;
};

// package2/dist/index.d.ts
export declare const BAZ: {
  // Why use the name specified in `package1/name`,
  // instead of the key in `package2/dependencies`?
  foo: Partial<import("package1").FOO>;
};

package.json:

// package1/package.json
{
  "name": "package1",
  "version": "1.0.0",
  "main": "index.js",
  "types": "index.d.ts",
  "exports": {
    ".": {
      "default": "./index.js",
      "types": "./index.d.ts"
    }
  }
}

// package2/package.json
{
  "name": "package2",
  "version": "1.0.0",
  "main": "index.js",
  "types": "index.d.ts",
  "devDependencies": {
    "typescript": "^4.8.3"
  },
  "dependencies": {
    "pkg1": "file:../package1"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "declaration": true,
    "moduleResolution": "nodenext",
    "outDir": "dist"
  }
}

🙁 Actual behavior

// package2/dist/index.d.ts
export declare const BAZ: {
  foo: Partial<import("package1").FOO>;
};

🙂 Expected behavior

// package2/dist/index.d.ts
export declare const BAZ: {
  foo: Partial<import("pkg1").FOO>;
};

貢獻者指南