0

In order to create nested static class i follow this

class Album {
    label: Album.AlbumLabel;
}
namespace Album {
    export class AlbumLabel { }
}

However, I need to export class Album too. When I do

export class Album {
    label: Album.AlbumLabel;
}
namespace Album {
    export class AlbumLabel { }
}

I get Individuals declarations in merged declaration 'Album' must be all exported or all local. How to fix it?

3
  • export namespace Album { ... } ? Commented Nov 15, 2018 at 16:08
  • @jcalz Do you mean, that I don't need to do export class Album and I only should do export namespace Album? Commented Nov 15, 2018 at 16:11
  • Export both. That's what "declarations must be all exported or all local" means. Either export both of them or neither of them. Commented Nov 15, 2018 at 16:13

1 Answer 1

0

Option one is to do as your told by the compiler and export both:

export class Album {
    label: Album.AlbumLabel;
}

export namespace Album {
    export class AlbumLabel { }
}

Option two is a shimmy variable, but you have a naming dilemma:

class Album {
    label: Album.AlbumLabel;
}

namespace Album {
    export class AlbumLabel { }
}

export const NameMe = Album;

The first option is a better choice (I reckon).

Imports

If you want to import AlbumLabel directly, don't nest it. It's in a module already, so have the module export Album and AlbumLabel.

If you keep the nesting you have to use either:

import { Album } from './component.js';

const a = new Album.AlbumLabel();

Or introduce a local name:

import { Album } from './component.js';
const AlbumLabel = Album.AlbumLabel;

const a = new AlbumLabel();

Here's the example that allows import { AlbumLabel } from './album';

export class Album {
    label: AlbumLabel;
}

export class AlbumLabel { }
Sign up to request clarification or add additional context in comments.

2 Comments

The answer was too long for a comment, so I updated the answer.
Thank you very much for explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.