microsoft / microsoft/TypeScript

Invalid import path rewrite in declaration file

Aperta
#60,331 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: Declaration Emit Help Wanted
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

"import paths", "imports rewrite"

🕗 Version & Regression Information
  • This changed between versions 5.5.4 and 5.6.3
⏯ Repository with repro

https://github.com/MariaSolOs/path-rewrite-bug

💻 Code

The linked repository contains all of the necessary code to reproduce the issue. This is a pnpm monorepo with 4 packages.

mod1 simply exports the following interface and makes it available outside the package:

// mod1/index.ts
export interface Foo {
  foo: string;
}
// mod1/package.json
{
  ...
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  }
}

mod2 depends on mod1 and exports its types.

// mod2/index.ts
import { Foo } from "mod1";

export const createFoo = (foo: string): Foo => ({ foo });

export type * from "mod1";
// mod2/package.json
{
  ...
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  },
  "dependencies": {
    "mod1": "workspace:*"
  }
}

mod3 depends on mod2 and exports a simple getFoo function using the imported function from mod2:

// mod3/index.ts
import { createFoo } from "mod2";

export const getFoo = () => createFoo("foo");
// mod3/package.json
{
  ...
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  },
  "dependencies": {
    "mod2": "workspace:*"
  }
}

Finally, mod4 depends on mod3 and uses getFoo to create another function:

// mod4/index.ts
import { getFoo } from "mod3";

export const foo = getFoo();
// mod4/package.json
{
  ...
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  },
  "dependencies": {
    "mod3": "workspace:*"
  }
}
🙁 Actual behavior

Because mod3 has an invalid index.d.ts, mod4 fails compilation when doing a lib check of mod3's type declaration files. This is the invalid declaration file from mod3:

export declare const getFoo: () => import("mod1").Foo;
//# sourceMappingURL=index.d.ts.map
🙂 Expected behavior

For the behavior from previous versions of TypeScript to be maintained: Since mod2 re-exports mod1s types, and since mod3 depends on mod2, compiling mod3 should produce this:

export declare const getFoo: () => import("mod2").Foo;
//# sourceMappingURL=index.d.ts.map
Additional information about the issue

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il monorepo pnpm path-rewrite-bug collegato e compila i pacchetti da mod1 a mod4 usando le versioni descritte nell’issue. Esamina il dist/index.d.ts generato di mod3 e verifica se la relativa dichiarazione importa Foo tramite mod2 invece che tramite mod1. È completato quando la dichiarazione generata corrisponde all’output previsto e mod4 supera la compilazione con i file di dichiarazione verificati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.