-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Avoid cast by providing type predicate to isExternalModuleAugmentation #22119
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
Conversation
25a1633
to
e1aee28
Compare
src/compiler/utilities.ts
Outdated
export function isAmbientModule(node: Node): boolean { | ||
return node && node.kind === SyntaxKind.ModuleDeclaration && | ||
((<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral || isGlobalScopeAugmentation(<ModuleDeclaration>node)); | ||
export interface AmbientModuleDeclaration extends ModuleDeclaration { body?: ModuleBlock; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we move this to types?
src/compiler/binder.ts
Outdated
} | ||
} | ||
else { | ||
const state = declareModuleSymbol(node); | ||
const { symbol } = node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did this move?
src/compiler/binder.ts
Outdated
@@ -1597,32 +1597,30 @@ namespace ts { | |||
if (hasModifier(node, ModifierFlags.Export)) { | |||
errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible); | |||
} | |||
const { name } = node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u can move this to the else block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Control flow was confused because node
was already an AmbientModuleDeclaration
and isExternalModuleAugmentation
re-checks that (thus node was never
in the else
). Broke it into two functions to avoid that.
This call to
addIndirectUser
turns out to be valid, but it took a while to figure that out -- can verify this with a type predicate.