microsoft / microsoft/TypeScript
Re-export class as part of a different namespace
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 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;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the panel.ts, panoramicpanel.ts, and serieschart.ts reproductions, then read the related TypeScript issue #4529. Investigate how namespace exports handle a class value and type, and define whether the requested PanoramicPanel access pattern should be supported; done means the behavior and its resulting diagnostics are resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100