@@ -16,7 +16,14 @@ 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 (
23+ `The type checker failed to look up a symbol for \`${ node . getText ( ) } '. ` +
24+ 'Perhaps, the checker was searching an outdated source.' ,
25+ ) ;
26+ }
2027
2128 return GetDeclarationFromSymbol ( symbol ) ;
2229 }
@@ -56,11 +63,13 @@ export namespace TypescriptHelper {
5663 export function GetParameterOfNode ( node : ts . EntityName ) : ts . NodeArray < ts . TypeParameterDeclaration > {
5764 const declaration : ts . Declaration = GetDeclarationFromNode ( node ) ;
5865
59- return ( declaration as Declaration ) . typeParameters ;
66+ const { typeParameters = ts . createNodeArray ( [ ] ) } : Declaration = ( declaration as Declaration ) ;
67+
68+ return typeParameters ;
6069 }
6170
62- export function GetTypeParameterOwnerMock ( declaration : ts . Declaration ) : ts . Declaration {
63- const typeDeclaration : ts . Declaration = ts . getTypeParameterOwner ( declaration ) ;
71+ export function GetTypeParameterOwnerMock ( declaration : ts . Declaration ) : ts . Declaration | undefined {
72+ const typeDeclaration : ts . Declaration | undefined = ts . getTypeParameterOwner ( declaration ) ;
6473
6574 // THIS IS TO FIX A MISSING IMPLEMENTATION IN TYPESCRIPT https://github.com/microsoft/TypeScript/blob/ba5e86f1406f39e89d56d4b32fd6ff8de09a0bf3/src/compiler/utilities.ts#L5138
6675 if ( typeDeclaration && ( typeDeclaration as Declaration ) . typeParameters ) {
@@ -79,7 +88,14 @@ export namespace TypescriptHelper {
7988 return propertyName . text ;
8089 }
8190
82- const symbol : ts . Symbol = TypeChecker ( ) . getSymbolAtLocation ( propertyName ) ;
91+ const symbol : ts . Symbol | undefined = TypeChecker ( ) . getSymbolAtLocation ( propertyName ) ;
92+
93+ if ( ! symbol ) {
94+ throw new Error (
95+ `The type checker failed to look up symbol for property: ${ propertyName . getText ( ) } .` ,
96+ ) ;
97+ }
98+
8399 return symbol . escapedName . toString ( ) ;
84100 }
85101
@@ -88,7 +104,7 @@ export namespace TypescriptHelper {
88104 }
89105
90106
91- export function getSignatureOfCallExpression ( node : ts . CallExpression ) : ts . Signature {
107+ export function getSignatureOfCallExpression ( node : ts . CallExpression ) : ts . Signature | undefined {
92108 const typeChecker : ts . TypeChecker = TypeChecker ( ) ;
93109
94110 return typeChecker . getResolvedSignature ( node ) ;
@@ -109,9 +125,9 @@ export namespace TypescriptHelper {
109125
110126 function GetDeclarationsForImport ( node : ImportDeclaration ) : ts . Declaration [ ] {
111127 const typeChecker : ts . TypeChecker = TypeChecker ( ) ;
112- const symbol : ts . Symbol = typeChecker . getSymbolAtLocation ( node . name ) ;
113- const originalSymbol : ts . Symbol = typeChecker . getAliasedSymbol ( symbol ) ;
128+ const symbol : ts . Symbol | undefined = node . name && typeChecker . getSymbolAtLocation ( node . name ) ;
129+ const originalSymbol : ts . Symbol | undefined = symbol && typeChecker . getAliasedSymbol ( symbol ) ;
114130
115- return originalSymbol . declarations ;
131+ return originalSymbol ? .declarations ?? [ ] ;
116132 }
117133}
0 commit comments