-
Notifications
You must be signed in to change notification settings - Fork 7
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
Declaration merging #28
Comments
That's the major reason I avoid namespaces in TS - the Ruby-esque ability to reopen and edit a definition in my experience makes code much harder to reason about. If you want to compose modules, imo you should use the current tools and import + re-export, rather than smooshing the code together. |
@ljharb merging modules is just one of the possibilities, anyway they will be in one file. Actually, I've never used namespaces merging in TypeScript. But merging namespace with function is pretty common use case to add logically related things to the function. Probably this will be the target use case for declaration merging. Yes, you will be able to merge modules by that way, but I can hardly imagine why one will need it since everything is in the same file. |
What if we optionally declare if a module can be merged? Something like partial classes in C#. This makes the reader aware that some members of the module might come from other merged declarations.
|
This proposal does not permit merging. The code sample at the beginning of the thread would cause an error at parse time. (However, this is not meant to pass judgement on TS declaration merging, which I don’t know if the world could live without!) |
Hello, will it be possible to merge declarations, like that:
This is how
namespaces
works in typescript (previously they called modules). PlaygroundOne huge benefit of namespaces is that they can be merge with functions declarations. Playground
This is a widely used pattern i.e. in react. Playground
The text was updated successfully, but these errors were encountered: