-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Error while accessing Namespace level variables from multiple files defining the same namespace. #6457
Comments
you need to export the variable to make it accessible across declarations. namespace System.Parent.Level1Child{
export var parameterToShareBetweenFiles: number = 0;
} |
Thanks that works. The resulting javascript defines the namespace twice rather than optimizing the code into one block of code. Is this by design? This is not optimal.
|
it is by design. there are scoping issues in place that warrants different closures. you can read more about this in #447 |
Thanks for referring the issue #447. The problem with exporting the internal variables in the namespace is that they are exposed to code outside the namespace. In my third file Below are the contents of
How can a developer protect the variables with in the namespace to be only accessible by code defined in the context of the namespace and not outside it? |
TypeScript does not have an |
I have two files
main.ts
andsecondfile.ts
defining a namespaceSystem.Parent.Level1Child
Below are the contents of
main.ts
Below are the contents of
secondfile.ts
Since I am extending the same namespace, I would expect that the
parameterToShareBetweenFiles
should be available in the secondfile.ts but the compiler throwsI believe this is a Bug and needs to be fixed. Because the error doesn't come if the class definition for ChildClass2 is brought into the
main.ts
file as below. Does this mean that the entire namespace has to be defined in a single file? That is very inconvenient especially with multiple developers contributing to the same namespace.The text was updated successfully, but these errors were encountered: