@@ -16,7 +16,11 @@ export namespace TypescriptHelper {
1616
1717 export function GetDeclarationFromNode ( node : ts . Node ) : ts . Declaration {
1818 const typeChecker : ts . TypeChecker = TypeChecker ( ) ;
19- const symbol : ts . Symbol = typeChecker . getSymbolAtLocation ( node ) ;
19+ const symbol : ts . Symbol | undefined = typeChecker . getSymbolAtLocation ( node ) ;
20+
21+ if ( ! symbol ) {
22+ throw new Error ( 'Unhandled' ) ;
23+ }
2024
2125 return GetDeclarationFromSymbol ( symbol ) ;
2226 }
@@ -56,11 +60,13 @@ export namespace TypescriptHelper {
5660 export function GetParameterOfNode ( node : ts . EntityName ) : ts . NodeArray < ts . TypeParameterDeclaration > {
5761 const declaration : ts . Declaration = GetDeclarationFromNode ( node ) ;
5862
59- return ( declaration as Declaration ) . typeParameters ;
63+ const { typeParameters = ts . createNodeArray ( [ ] ) } : Declaration = ( declaration as Declaration ) ;
64+
65+ return typeParameters ;
6066 }
6167
62- export function GetTypeParameterOwnerMock ( declaration : ts . Declaration ) : ts . Declaration {
63- const typeDeclaration : ts . Declaration = ts . getTypeParameterOwner ( declaration ) ;
68+ export function GetTypeParameterOwnerMock ( declaration : ts . Declaration ) : ts . Declaration | undefined {
69+ const typeDeclaration : ts . Declaration | undefined = ts . getTypeParameterOwner ( declaration ) ;
6470
6571 // THIS IS TO FIX A MISSING IMPLEMENTATION IN TYPESCRIPT https://github.com/microsoft/TypeScript/blob/ba5e86f1406f39e89d56d4b32fd6ff8de09a0bf3/src/compiler/utilities.ts#L5138
6672 if ( typeDeclaration && ( typeDeclaration as Declaration ) . typeParameters ) {
@@ -79,7 +85,12 @@ export namespace TypescriptHelper {
7985 return propertyName . text ;
8086 }
8187
82- const symbol : ts . Symbol = TypeChecker ( ) . getSymbolAtLocation ( propertyName ) ;
88+ const symbol : ts . Symbol | undefined = TypeChecker ( ) . getSymbolAtLocation ( propertyName ) ;
89+
90+ if ( ! symbol ) {
91+ throw new Error ( 'Unhandled' ) ;
92+ }
93+
8394 return symbol . escapedName . toString ( ) ;
8495 }
8596
@@ -88,7 +99,7 @@ export namespace TypescriptHelper {
8899 }
89100
90101
91- export function getSignatureOfCallExpression ( node : ts . CallExpression ) : ts . Signature {
102+ export function getSignatureOfCallExpression ( node : ts . CallExpression ) : ts . Signature | undefined {
92103 const typeChecker : ts . TypeChecker = TypeChecker ( ) ;
93104
94105 return typeChecker . getResolvedSignature ( node ) ;
@@ -109,9 +120,9 @@ export namespace TypescriptHelper {
109120
110121 function GetDeclarationsForImport ( node : ImportDeclaration ) : ts . Declaration [ ] {
111122 const typeChecker : ts . TypeChecker = TypeChecker ( ) ;
112- const symbol : ts . Symbol = typeChecker . getSymbolAtLocation ( node . name ) ;
113- const originalSymbol : ts . Symbol = typeChecker . getAliasedSymbol ( symbol ) ;
123+ const symbol : ts . Symbol | undefined = node . name && typeChecker . getSymbolAtLocation ( node . name ) ;
124+ const originalSymbol : ts . Symbol | undefined = symbol && typeChecker . getAliasedSymbol ( symbol ) ;
114125
115- return originalSymbol . declarations ;
126+ return originalSymbol ? .declarations ?? [ ] ;
116127 }
117128}
0 commit comments