@@ -286,13 +286,18 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
286286
287287 // tslint:disable-next-line:cyclomatic-complexity
288288 function isTypePropertyExternal ( type : ts . Type , typePropertyName : string ) : boolean {
289- const symbol = type . getSymbol ( ) ;
290- const propertySymbol = typeChecker . getPropertyOfType ( type , typePropertyName ) ;
289+ // if a type is unknown or any - they should be interpret as a public ones
290+ if ( type . flags & ts . TypeFlags . Unknown || type . flags & ts . TypeFlags . Any ) {
291+ return true ;
292+ }
291293
292294 if ( type . flags & ts . TypeFlags . IndexedAccess ) {
293295 return isTypePropertyExternal ( typeChecker . getApparentType ( type ) , typePropertyName ) ;
294296 }
295297
298+ const symbol = type . getSymbol ( ) ;
299+ const propertySymbol = typeChecker . getPropertyOfType ( type , typePropertyName ) ;
300+
296301 if ( type . flags & ts . TypeFlags . Object ) {
297302 const objectType = type as ts . ObjectType ;
298303 // treat any tuple property as "external"
@@ -353,7 +358,21 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
353358 // tslint:disable-next-line:cyclomatic-complexity
354359 function getNodeVisibilityType ( node : ts . Expression | ts . Identifier | ts . StringLiteral | ts . BindingElement ) : VisibilityType {
355360 if ( ts . isPropertyAssignment ( node . parent ) || ts . isShorthandPropertyAssignment ( node . parent ) ) {
356- const type = typeChecker . getContextualType ( node . parent . parent ) ;
361+ let expressionToGetTypeFrom : ts . Expression = node . parent . parent ;
362+ let lastKnownExpression : ts . AsExpression | ts . ObjectLiteralExpression = node . parent . parent ;
363+ let currentNode : ts . Node = node . parent . parent . parent ;
364+
365+ while ( ts . isParenthesizedExpression ( currentNode ) || ts . isAsExpression ( currentNode ) ) {
366+ if ( ts . isAsExpression ( currentNode ) ) {
367+ expressionToGetTypeFrom = lastKnownExpression ;
368+ lastKnownExpression = currentNode ;
369+ }
370+
371+ currentNode = currentNode . parent ;
372+ }
373+
374+ // to get correct contextual type we need to provide the previous last expression rather than the last one
375+ const type = typeChecker . getContextualType ( expressionToGetTypeFrom ) ;
357376 if ( type !== undefined && isTypePropertyExternal ( type , node . getText ( ) ) ) {
358377 return VisibilityType . External ;
359378 }
0 commit comments