Re-export class as part of a different namespace

未关闭
#28,292 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
typescript
领域
compilers

调研方向

先从 panel.ts、panoramicpanel.ts 和 serieschart.ts 的复现开始,然后阅读相关的 TypeScript issue #4529。调查命名空间导出如何处理类值和类类型,并确定是否应支持所请求的 PanoramicPanel 访问模式;当该行为及其产生的诊断信息得到解决时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

In Discussion Suggestion

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;
主要语言
Go
星标
111k
派生
14.4k
平均合并
1 天 19 小时
30 天内合并 PR
117

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。