@@ -110,13 +110,7 @@ export class MockDefiner {
110110  public  createMockFactory ( declaration : ts . Declaration ) : void { 
111111    const  thisFileName : string  =  this . _fileName ; 
112112
113-     const  key : string  |  undefined  =  this . getDeclarationKeyMap ( declaration ) ; 
114- 
115-     if  ( ! key )  { 
116-       throw  new  Error ( 
117-         `Failed to obtain key while creating mock factory for \`${ declaration . getText ( ) }  , 
118-       ) ; 
119-     } 
113+     const  key : string  =  this . getDeclarationKeyMap ( declaration ) ; 
120114
121115    this . _factoryCache . set ( declaration ,  key ) ; 
122116
@@ -152,24 +146,22 @@ export class MockDefiner {
152146    return  this . _getCallGetFactory ( key ) ; 
153147  } 
154148
155-   public  getDeclarationKeyMap ( declaration : ts . Declaration ) : string  |  undefined  { 
149+   public  getDeclarationKeyMap ( declaration : ts . Declaration ) : string  { 
150+     let  key : string  |  undefined ; 
151+ 
156152    if  ( ! this . _declarationCache . has ( declaration ) )  { 
157-       const   key :  string  =  this . _factoryUniqueName . createForDeclaration ( declaration  as  PossibleDeclaration ) ; 
153+       key  =  this . _factoryUniqueName . createForDeclaration ( declaration  as  PossibleDeclaration ) ; 
158154
159155      this . _declarationCache . set ( declaration ,  key ) ; 
160156    } 
161157
162-     return  this . _declarationCache . get ( declaration ) ; 
158+     // NOTE: TypeScript does not support inference through has/get, but we know 
159+     // for a fact that the result here is a string! 
160+     return  ( key  ||  this . _declarationCache . get ( declaration ) )  as  string ; 
163161  } 
164162
165163  public  storeRegisterMockFor ( declaration : ts . Declaration ,  factory : ts . FunctionExpression ) : void { 
166-     const  key : string  |  undefined  =  this . getDeclarationKeyMap ( declaration ) ; 
167- 
168-     if  ( ! key )  { 
169-       throw  new  Error ( 
170-         `Failed to obtain key while storing mock for \`${ declaration . getText ( ) }  , 
171-       ) ; 
172-     } 
164+     const  key : string  =  this . getDeclarationKeyMap ( declaration ) ; 
173165
174166    this . _registerMockFactoryCache . set ( declaration ,  key ) ; 
175167
@@ -207,13 +199,7 @@ export class MockDefiner {
207199      return  cachedFactory ; 
208200    } 
209201
210-     const  key : string  |  undefined  =  this . getDeclarationKeyMap ( declaration ) ; 
211- 
212-     if  ( ! key )  { 
213-       throw  new  Error ( 
214-         `Failed to obtain key while resolving factory identifier (internal) for \`${ declaration . getText ( ) }  , 
215-       ) ; 
216-     } 
202+     const  key : string  =  this . getDeclarationKeyMap ( declaration ) ; 
217203
218204    this . _factoryCache . set ( declaration ,  key ) ; 
219205
0 commit comments