microsoft / microsoft/TypeScript

No ways to do an alias of an exported type inside a namespace

Offen
#40,771 2 Kommentare 12 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

TypeScript Version: 3.9.7

Search Terms:
export type alias namespace

Code
With import type, in case of long namespaces encapsulation, there's no way to do an alias of the namespaces.
We are forced to alias the final types / interfaces

file types.ts

type A = {}
type B = {}
type C = {}

export type {
    A,
    B,
    C
};

file namespace1.ts

import type * as namespace1 from 'types';

export type {namespace1}

file namespace2.ts

import type * as namespace2 from 'namespace1';

export type {namespace2}

file finalUsage.ts

import type {namespace2} from 'namespace2';

type A = namespace2.namespace1.A; // this is working
namespace aliasNamespaces2 {
   export import namespace1 = namespace2.namespace1; // fails with message 'An import alias cannot reference a declaration that was imported using 'import type'. '
}

Expected behavior:
we need a way to make a shortcut of namespaces2.namespace1

Actual behavior:
Cannot do it: we are forced to aliasthe final types namespaces2.namespace1.A

Playground Link:

Related Issues:

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

Beginne damit, das Verhalten in den Beispieldateien types.ts, namespace1.ts, namespace2.ts und finalUsage.ts mit dem gemeldeten TypeScript 3.9.7-Setup zu reproduzieren. Verfolge die Verarbeitung von import type aliases und namespace references und definiere und teste anschließend eine unterstützte Möglichkeit, namespace2.namespace1 ohne den aktuellen import-type error zu verkürzen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

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