tsoa
tsoa copied to clipboard
Namespaced cross-references not recognized without parent namespace
When referencing an interface in the same namespace, tsoa does not recognize the referenced namespace without the parent namespace attached
Sorting
-
I'm submitting a ...
- [ X] bug report
-
I confirm that I
- [ X] used the search to make sure that a similar issue hasn't already been submit
Expected Behavior
I should be able to import a Namespace that has references to other types in the same namespace.
export Namespace Shape {
export interface Dimension {
}
export interface Square {
length: Dimension
}
}
import 'Shape' from './models/types';
...Promise<Shape.Square>
Current Behavior
Currently returns:
UnhandledPromiseRejectionWarning: Error: No matching model found for referenced type Dimension
In order to get it to work, we must do:
export Namespace Shape {
export interface Square {
length: Shape.Dimension
}
}
import 'Shape' from './models/types';
...Promise<Shape.Square>
Possible Solution
Steps to Reproduce
- Add namespace to model
- Add a cross-reference to a type in the namespaced model
- Run route generator
Context (Environment)
Version of the library: 2.51 Version of NodeJS: v12.8.0
- Confirm you were using yarn not npm: [X ]
Detailed Description
Breaking change?
Out of curiosity, why are you using namespaces at all?
I ask because, the TypeScript documentation mentions that mixing modules and namespaces is discouraged, and in fact it mentions that namespaces themselves are unnecessary:
"To reiterate why you shouldn’t try to namespace your module contents, the general idea of namespacing is to provide logical grouping of constructs and to prevent name collisions. Because the module file itself is already a logical grouping, and its top-level name is defined by the code that imports it, it’s unnecessary to use an additional module layer for exported objects."
https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html#needless-namespacing
That being said, I think it's totally reasonable to look into this bug-fix/feature (not sure if this ever worked). But since namespaces are discouraged, this issue will be a slightly lower priority.
So although we have the established workaround of not using namespaces, I have marked this issue as "help wanted"
so that contributors will be made aware that this is free-game to be worked on.