Allow namespace declaration merging for all objects #51417
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Uh oh!
There was an error while loading. Please reload this page.
Suggestion
π Search Terms
Declaration merging, variable, object
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
In TypeScript this is allowed:
And this is the JavaScript output:
But this "throws" an
error TS2300
:Regardless of the fact that the JavaScript output is actually what I would expect:
And so is its result:
π Motivating Example
I wanted to define an extensible pipeline of operations.
Those operations need to be executed in a specific order and be accessible separately by name.
This is a simplified example:
This code gets compiled and works as espected, but still "throws" an
error TS2300
π» Use Cases
My objective was to create an object which is both a valid array and a namespace. The reason I wanted to do it with a namespace is because it allows me to define both the array elements and the keys at the same time (Both in the type and the runtime object) and easily merge all the partial definitions of the namespace. Since it is phisically possible to merge a namespace to every object type I wonder why it is not allowed
The text was updated successfully, but these errors were encountered: