Skip to content

Commit e73d58e

Browse files
author
Andy
authored
findAllReferences: Type parameter is not globally visible (microsoft#16419)
* findAllReferences: Type parameter is not globally visible * Add test for merged interface * Clean up comment
1 parent 39e0cc6 commit e73d58e

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/services/findAllReferences.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,15 @@ namespace ts.FindAllReferences.Core {
652652
return undefined;
653653
}
654654

655-
// If the symbol has a parent, it's globally visible.
656-
// Unless that parent is an external module, then we should only search in the module (and recurse on the export later).
657-
// But if the parent is a module that has `export as namespace`, then the symbol *is* globally visible.
658-
if (parent && !((parent.flags & SymbolFlags.Module) && isExternalModuleSymbol(parent) && !parent.globalExports)) {
655+
/*
656+
If the symbol has a parent, it's globally visible unless:
657+
- It's a private property (handled above).
658+
- It's a type parameter.
659+
- The parent is an external module: then we should only search in the module (and recurse on the export later).
660+
- But if the parent has `export as namespace`, the symbol is globally visible through that namespace.
661+
*/
662+
const exposedByParent = parent && !(symbol.flags & SymbolFlags.TypeParameter);
663+
if (exposedByParent && !((parent.flags & SymbolFlags.Module) && isExternalModuleSymbol(parent) && !parent.globalExports)) {
659664
return undefined;
660665
}
661666

@@ -682,7 +687,7 @@ namespace ts.FindAllReferences.Core {
682687
// declare module "a" { export type T = number; }
683688
// declare module "b" { import { T } from "a"; export const x: T; }
684689
// 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.)
685-
return parent ? scope.getSourceFile() : scope;
690+
return exposedByParent ? scope.getSourceFile() : scope;
686691
}
687692

688693
function getPossibleSymbolReferencePositions(sourceFile: SourceFile, symbolName: string, container: Node = sourceFile): number[] {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////interface I<[|{| "isWriteAccess": true, "isDefinition": true |}T|]> { a: [|T|] }
4+
////interface I<[|{| "isWriteAccess": true, "isDefinition": true |}T|]> { b: [|T|] }
5+
6+
verify.singleReferenceGroup("(type parameter) T in I<T>");

0 commit comments

Comments
 (0)