I have a class that includes an enum
:
class appearance{
// ... stuff ...
enum color {BLUE, RED, GREEN};
};
I would like to attach part of the namespace (with using
) so that I can refer to the value of the BLUE
simply as BLUE
, rather than appearance::BLUE
. At the same time, I would like to keep the enum
within the class{}
, since I think that is most natural. I have tried various combinations of namespace
and using
, but to no avail.
Any suggestions ???
The export as namespace form creates a global variable so it can be used without importing, but you may still import it with the import { name } from "some-library" form of import.
The namespace is used for logical grouping of functionalities. A namespace can include interfaces, classes, functions and variables to support a single or a group of related functionalities. A namespace can be created using the namespace keyword followed by the namespace name.
Inside a namespace, no two classes can have the same name.
Namespace Declaration We can declare the namespace as below. To access the interfaces, classes, functions, and variables in another namespace, we can use the following syntax. If the namespace is in separate TypeScript file, then it must be referenced by using triple-slash (///) reference syntax.
I don't think it can be done. AFAIK, you can use using appearance::color
in another class or structure as stipulated here.
A using declaration in a class A may name one of the following:
A member of a base class of A
A member of an anonymous union that is a member of a base class of A
An enumerator for an enumeration type that is a member of a base class of A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With