microsoft / microsoft/TypeScript

Named import for 'any'-typed module doesn't work

Offen
#42,506 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Bug Report

🔎 Search Terms

any module export assignment named import

🕗 Version & Regression Information

TypeScript v4.1.2

💻 Code

mock.d.ts

declare const _: any;
export = _;

example.ts

import { a } from "./mock";

import * as b from "./mock";
const { c } = b;

const { d } = await import("./mock");

console.log(a, c, d);

tsconfig.json

{
  "compilerOptions": {
    "module": "ESNext",
    "strict": true,
    "target": "ESNext",
  },
  "include": [
    "./**/*.ts"
  ]
}
🙁 Actual behavior

The first import returns the diagnostic:

error TS2305: Module '"./mock"' has no exported member 'a'.

While c and d do not error.

🙂 Expected behavior

With an export being effectively any, I would expect default, namespace, dynamic and named imports to all behave as if the module was any. I cannot find any other way to declare a module in a fashion where the compiler treats any import from that module as any and does not issue diagnostics.

As implied in the above, there are certain situations where there is a need to "mock" a module where its shape cannot be statically determined at compile time.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere den Bericht mit mock.d.ts, example.ts und tsconfig.json und verfolge anschließend, wie der TypeScript-Compiler benannte Importe aus einem als any typisierten Export-Assignment-Modul behandelt. Als erledigt gilt die Aufgabe, wenn der benannte Import nicht mehr TS2305 meldet und gleichzeitig das für Namespace- und dynamische Importe gezeigte Verhalten beibehalten wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.