Skip to content

Declaration file has wrong import path for composite projects #31696

@timocov

Description

@timocov

TypeScript Version: 3.6.0-dev.20190531, 3.5.1

Search Terms: composite projects, declaration files, paths

Code

  1. Download zip with the project project.zip
  2. npm install
  3. npm run build
  4. cat lib/src/sub-project-2/index.d.ts
  5. cat lib-non-composite/src/sub-project-2/index.d.ts
  6. Compare these files. In my case it's:

file from composite output (./lib):

declare const variable: {
    key: import("../../lib/src/common/nominal").Nominal<string, "MyNominal">;
};
export declare function getVar(): keyof typeof variable;
export {};

file from non-composite output (./lib-non-composite):

declare const variable: {
    key: import("../common/nominal").Nominal<string, "MyNominal">;
};
export declare function getVar(): keyof typeof variable;
export {};

There we have 2 things:

  1. Output from build mode (composite project) has invalid import path (../../lib/src/common/nominal in lib/src/sub-project-2/index.d.ts refers to root/lib/lib/src/common/nominal, but this file does not exist - there should be ../../../, not ../..). Output from non-composite project has valid path.
  2. I don't know why, but the compiler adds import() and "inline" declaration instead of importing it from file where it declared for both composite and non-composite projects. Even if it works for non-composite project, it looks strange.

I'm not sure about 2, but the first looks like a bug because it produces invalid typings.

Related Issues: #25600

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions