@@ -287,6 +287,7 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
287287 // tslint:disable-next-line:cyclomatic-complexity
288288 function isTypePropertyExternal ( type : ts . Type , typePropertyName : string ) : boolean {
289289 const symbol = type . getSymbol ( ) ;
290+ const propertySymbol = typeChecker . getPropertyOfType ( type , typePropertyName ) ;
290291
291292 if ( type . flags & ts . TypeFlags . Object ) {
292293 const objectType = type as ts . ObjectType ;
@@ -295,11 +296,13 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
295296 return true ;
296297 }
297298
298- // because of we can't get where a property come from in mapped types
299- // let's check the whole its type explicitly
300- // thus let's treat any property of a mapped type as "external" if its parent type is external
299+ // in case when we can't get where a property come from in mapped types
300+ // let's check the whole type explicitly
301+ // thus in case of when property doesn't have a declaration let's treat any property of a mapped type as "external" if its parent type is external
302+ // e.g. Readonly<Foo>.field will look for `field` in _Foo_ type (not in Readonly<Foo>), but { [K in 'foo' | 'bar']: any } won't
301303 // perhaps it would be awesome to handle exactly property we have, but ¯\_(ツ)_/¯
302- if ( ( objectType . objectFlags & ts . ObjectFlags . Mapped ) && symbol !== undefined && getSymbolVisibilityType ( symbol ) === VisibilityType . External ) {
304+ const propertyHasDeclarations = propertySymbol !== undefined ? getDeclarationsForSymbol ( propertySymbol ) . length !== 0 : false ;
305+ if ( ( objectType . objectFlags & ts . ObjectFlags . Mapped ) && symbol !== undefined && ! propertyHasDeclarations && getSymbolVisibilityType ( symbol ) === VisibilityType . External ) {
303306 return true ;
304307 }
305308 }
@@ -328,7 +331,6 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
328331 }
329332 }
330333
331- const propertySymbol = typeChecker . getPropertyOfType ( type , typePropertyName ) ;
332334 if ( propertySymbol === undefined ) {
333335 return false ;
334336 }
0 commit comments