microsoft / microsoft/TypeScript

Declaration emit reveals paths within dependency that were not referred to in the source file

Ouverte
#38,111 10 commentaires 5 réactions 1 personne assignée Voir sur GitHub

@weswigham y travaille déjà.

Depuis le 1/6/2020.

Needs Investigation Rescheduled
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

Context:

  • Generating declaration files

Declaration emit reveals paths within dependency that were not referred to in the source file:

export declare const instance: import("dependency/internal-types").TheInterface;

This is a problem because changing paths within a dependency can break a dependent package.

TypeScript Version: 3.9.0-dev.20200212

Search Terms:

Code

node_modules/@types/dependency/entrypoint.d.ts

import { TheInterface } from "./internal-types";
export { TheInterface };
export declare function getInstance(): TheInterface;

node_modules/@types/dependency/internal-types.d.ts

export interface TheInterface {}

node_modules/@types/dependency/index.d.ts

// empty - doesn't matter for this example

example.ts

import { getInstance } from "dependency/entrypoint";
export const instance = getInstance();

src/app/tsconfig.json

{
    "compilerOptions": {
        "declaration": true,
    }
}

Expected behavior:

example.d.ts

export declare const instance: import("dependency/entrypoint").TheInterface;

Actual behavior:

example.d.ts

export declare const instance: import("dependency/internal-types").TheInterface;

It seems that part of the solution could involve having the compiler avoid using relative paths in types (import("<relativepath>").<typename>) if the relativepath is outside the project.

Repro Repo: https://github.com/mheiber/repro-rel-import-inlining

Related Issues:

  • Declaration emit should not inline type definitions - #37151
  • Proposal: Bundling TS module type definitions - #4433

Issue written with the help of: @rricard, @robpalme and @mkubilayk

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.