diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 204de12a10c..ad26dae2115 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -652,10 +652,15 @@ namespace ts.FindAllReferences.Core { return undefined; } - // If the symbol has a parent, it's globally visible. - // Unless that parent is an external module, then we should only search in the module (and recurse on the export later). - // But if the parent is a module that has `export as namespace`, then the symbol *is* globally visible. - if (parent && !((parent.flags & SymbolFlags.Module) && isExternalModuleSymbol(parent) && !parent.globalExports)) { + /* + If the symbol has a parent, it's globally visible unless: + - It's a private property (handled above). + - It's a type parameter. + - The parent is an external module: then we should only search in the module (and recurse on the export later). + - But if the parent has `export as namespace`, the symbol is globally visible through that namespace. + */ + const exposedByParent = parent && !(symbol.flags & SymbolFlags.TypeParameter); + if (exposedByParent && !((parent.flags & SymbolFlags.Module) && isExternalModuleSymbol(parent) && !parent.globalExports)) { return undefined; } @@ -682,7 +687,7 @@ namespace ts.FindAllReferences.Core { // declare module "a" { export type T = number; } // declare module "b" { import { T } from "a"; export const x: T; } // So we must search the whole source file. (Because we will mark the source file as seen, we we won't return to it when searching for imports.) - return parent ? scope.getSourceFile() : scope; + return exposedByParent ? scope.getSourceFile() : scope; } function getPossibleSymbolReferencePositions(sourceFile: SourceFile, symbolName: string, container: Node = sourceFile): number[] { diff --git a/tests/cases/fourslash/findAllRefsTypeParameterInMergedInterface.ts b/tests/cases/fourslash/findAllRefsTypeParameterInMergedInterface.ts new file mode 100644 index 00000000000..d489a51ccdd --- /dev/null +++ b/tests/cases/fourslash/findAllRefsTypeParameterInMergedInterface.ts @@ -0,0 +1,6 @@ +/// + +////interface I<[|{| "isWriteAccess": true, "isDefinition": true |}T|]> { a: [|T|] } +////interface I<[|{| "isWriteAccess": true, "isDefinition": true |}T|]> { b: [|T|] } + +verify.singleReferenceGroup("(type parameter) T in I");