-
Notifications
You must be signed in to change notification settings - Fork 200
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
Shorthand ambient modules do not have a body #924
Comments
Yes, this is a bug. I think probably in this case it shouldn't show up for any export interface NamespaceDeclaration extends ModuleDeclaration {
readonly name: Identifier;
readonly body: NamespaceBody;
}
export interface ModuleDeclaration extends DeclarationStatement, JSDocContainer {
readonly kind: SyntaxKind.ModuleDeclaration;
readonly parent: ModuleBody | SourceFile;
readonly name: ModuleName;
readonly body?: ModuleBody | JSDocNamespaceDeclaration;
} Given the compiler does the above, I think probably a |
Just looking into this now... ts-morph doesn't represent ambient module declarations acurately. Also, I discovered there is an internal export interface AmbientModuleDeclaration extends ModuleDeclaration {
readonly body?: ModuleBlock;
} That said, these types seem to be just for assertions. I've been thinking about this more and ts-morph relies heavily on having a mapping from syntax kind to wrapped node. Given I'll make these updates before the next TS major release on Feb 23rd. |
BREAKING CHANGE: ts-morph did not properly support some ambient and all shorthand ambient module declarations. Now `NamespaceDeclaration` is `ModuleDeclaration`. You will need to rename anything that references "Namespace" and change it to "Module".
Describe the bug
Typescript allows declaring ambient modules without a body, known as shorthand ambient modules.
Operations accessing the body of this kind of modules fail with the error
Bodied node should have a body.
.Version: 9.1.0
Typescript version: 4.1.3
To Reproduce
Expected behavior
Shorthand ambient modules should not be considered bodied modules.
Workaround
A possible workaround to identify shorthand ambient modules consists in checking if they have any
ModuleBlock
descendants.The text was updated successfully, but these errors were encountered: