microsoft / microsoft/TypeScript

Re-export class as part of a different namespace

Ouverte
#28,292 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

In Discussion Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

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;

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par les reproductions de panel.ts, panoramicpanel.ts et serieschart.ts, puis lisez l’issue TypeScript associée, #4529. Étudiez la manière dont les exports d’espace de noms gèrent une valeur de classe et un type de classe, et déterminez si le modèle d’accès demandé pour PanoramicPanel doit être pris en charge ; le travail est considéré comme terminé lorsque le comportement et les diagnostics qui en résultent sont résolus.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.