Avoid cast by providing type predicate to isExternalModuleAugmentation#22119
Merged
3 commits merged intoMar 6, 2018
Merged
Conversation
25a1633 to
e1aee28
Compare
mhegazy
reviewed
Feb 22, 2018
| 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; } |
Contributor
There was a problem hiding this comment.
should we move this to types?
mhegazy
reviewed
Feb 22, 2018
| } | ||
| else { | ||
| const state = declareModuleSymbol(node); | ||
| const { symbol } = node; |
mhegazy
reviewed
Feb 22, 2018
| 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; |
Contributor
There was a problem hiding this comment.
u can move this to the else block
Author
There was a problem hiding this comment.
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.
mhegazy
approved these changes
Mar 6, 2018
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This call to
addIndirectUserturns out to be valid, but it took a while to figure that out -- can verify this with a type predicate.