mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 00:36:29 -05:00
Add 'isNamedDeclaration' helper to reduce casts (#22089)
* Add 'isNamedDeclaration' helper to reduce casts * Add assertion * Remove assertion
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user