microsoft / microsoft/TypeScript
Re-export class as part of a different namespace
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
This is similar to https://github.com/Microsoft/TypeScript/issues/4529, but that issue was closed before it got any real traction.
Setup:
// panel.ts
export class Panel {
constructor() {}
}
export namespace Panel {
export enum GridLineTypeFlags {
NONE = 0x00
}
export enum NormalizationType {
NONE,
SEPARATE_AXIS
}
}
export default Panel;
// panoramicpanel.ts
export class PanoramicPanel {
constructor() {}
public toString(): string {
return 'PanoramicPanel';
}
}
In the serieschart.ts file I'm trying to export the PanoramicPanel class in the same way as I'm exporting the Panel class and namespace, so both can be accessed in my application code as new SeriesChart.PanoramicPanel() and as a type.
The only way I found to make this work is the following, where using the import export syntax gives an error. Is there a reason why there would be an error?
(And because we have a lot of code which depends on the structure of this module, we unfortunately can not get rid of the namespaces.)
// serieschart.ts
import { Panel as PanelType } from './panel';
import { PanoramicPanel as PanoramicPanelType} from './panoramicpanel';
class SeriesChart {
}
namespace SeriesChart {
export import Panel = PanelType;
// export import PanoramicPanel = PanoramicPanelType; <- Error: PanoramicPanelType only refers to a type but is used as a namespace here
// export { PanoramicPanelType as PanoramicPanel} <- Error: Export declarations are not permitted in namespace
// this works, but is very counter intuitive
export type PanoramicPanel = PanoramicPanelType;
export const PanoramicPanel = PanoramicPanelType;
}
export default SeriesChart;
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den Reproduktionen von panel.ts, panoramicpanel.ts und serieschart.ts und lies anschließend das zugehörige TypeScript-Issue #4529. Untersuche, wie Namespace-Exporte einen Klassenwert und einen Klassentyp behandeln, und lege fest, ob das angeforderte Zugriffsmuster für PanoramicPanel unterstützt werden sollte; abgeschlossen ist die Aufgabe, wenn das Verhalten und die daraus resultierenden Diagnosen behoben sind.
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