Add 'isNamedDeclaration' helper to reduce casts (#22089)

* Add 'isNamedDeclaration' helper to reduce casts

* Add assertion

* Remove assertion
This commit is contained in:
Andy
2018-03-08 07:50:25 -08:00
committed by GitHub
parent 88ba1ef2de
commit 2676786e7f
2 changed files with 8 additions and 3 deletions

View File

@@ -315,7 +315,7 @@ namespace ts {
}
function getDisplayName(node: Declaration): string {
return (node as NamedDeclaration).name ? declarationNameToString((node as NamedDeclaration).name) : unescapeLeadingUnderscores(getDeclarationName(node));
return isNamedDeclaration(node) ? declarationNameToString(node.name) : unescapeLeadingUnderscores(getDeclarationName(node));
}
/**
@@ -383,8 +383,8 @@ namespace ts {
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
}
else {
if ((node as NamedDeclaration).name) {
(node as NamedDeclaration).name.parent = node;
if (isNamedDeclaration(node)) {
node.name.parent = node;
}
// Report errors every position with duplicate declaration

View File

@@ -4250,6 +4250,11 @@ namespace ts {
return declaration.name || nameForNamelessJSDocTypedef(declaration);
}
/** @internal */
export function isNamedDeclaration(node: Node): node is NamedDeclaration & { name: DeclarationName } {
return !!(node as NamedDeclaration).name; // A 'name' property should always be a DeclarationName.
}
export function getNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined {
if (!declaration) {
return undefined;