microsoft / microsoft/TypeScript
Re-export class as part of a different namespace
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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;
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con le riproduzioni di panel.ts, panoramicpanel.ts e serieschart.ts, quindi leggi la issue TypeScript correlata #4529. Analizza come le esportazioni di namespace gestiscono un valore di classe e un tipo di classe e definisci se il pattern di accesso richiesto per PanoramicPanel debba essere supportato; il lavoro è completato quando il comportamento e le relative diagnostiche risultanti sono risolti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100