-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntatic sugar for callable namespaces (functions as namespace) #23735
Comments
@AlCalzone I'm sure that they are not even related. The first is interface declaration which is a type rather than an object at runtime while functions are objects being created during runtime. As for the second one, I don't see how it's related to this at all. |
@mhegazy Okay, I can see how #15058 would "solve" my problem but it has its own limitation:
|
We already have a syntax for function + namespace; that already cover all your needs up there. The request here is to add a new syntax for shorter declaration of function+namespace combo. So it covering all the features of the existing syntactic form is not the goal. Here is my rational, First, we should not have two ways of declaring the same construct, unless there is a very good reason. Second, the proposal in the OP does not get us closer to a natural JS model. And it is one of our goals to be as close to JS as possible; we have already said we want to do the proposal in #15058, as it is identical to what you write in JS. that all said, if we were to add a new shorter form, it would be the one in #15058. And as for 1, 2 and 3, you should use As for 4, no, that would not be allowed. only top-level assignments would be allowed with #15058. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
@mhegazy where is that can u post a link? |
https://www.typescriptlang.org/docs/handbook/declaration-merging.html scroll down to about 2/3. function buildLabel(name: string): string {
return buildLabel.prefix + name + buildLabel.suffix;
}
namespace buildLabel {
export let suffix = "";
export let prefix = "Hello, ";
} |
I have a suggestion: I love to write callable namespaces but I don't want to write its name twice (one for function, one for namespace), so I propose a syntax sugar for this:
This should be equivalent to:
Search Terms:
callable namespace syntax sugar
The text was updated successfully, but these errors were encountered: