From 737fda928c8ec41efda4496d2adbc104a75bdd7d Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 17 Jan 2019 14:45:40 -0800 Subject: [PATCH] Don't treat interfaces as implementations ...even if they're in ambient contexts. Same for type aliases. --- src/services/findAllReferences.ts | 3 ++- .../fourslash/goToImplementationInterface_09.ts | 12 ++++++++++++ .../fourslash/goToImplementationTypeAlias_00.ts | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/goToImplementationInterface_09.ts create mode 100644 tests/cases/fourslash/goToImplementationTypeAlias_00.ts diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index bac1811f429..54202322260 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1682,7 +1682,8 @@ namespace ts.FindAllReferences.Core { function isImplementation(node: Node): boolean { return !!(node.flags & NodeFlags.Ambient) - || (isVariableLike(node) ? hasInitializer(node) + ? !(isInterfaceDeclaration(node) || isTypeAliasDeclaration(node)) + : (isVariableLike(node) ? hasInitializer(node) : isFunctionLikeDeclaration(node) ? !!node.body : isClassLike(node) || isModuleOrEnumDeclaration(node)); } diff --git a/tests/cases/fourslash/goToImplementationInterface_09.ts b/tests/cases/fourslash/goToImplementationInterface_09.ts new file mode 100644 index 00000000000..5706dea5bb6 --- /dev/null +++ b/tests/cases/fourslash/goToImplementationInterface_09.ts @@ -0,0 +1,12 @@ +/// + +// Should go to object literals within cast expressions when invoked on interface + +// @Filename: def.d.ts +//// export interface Interface { P: number } + +// @Filename: ref.ts +//// import { Interface } from "./def"; +//// const c: I/*ref*/nterface = [|{ P: 2 }|]; + +verify.allRangesAppearInImplementationList("ref"); \ No newline at end of file diff --git a/tests/cases/fourslash/goToImplementationTypeAlias_00.ts b/tests/cases/fourslash/goToImplementationTypeAlias_00.ts new file mode 100644 index 00000000000..6eb997c2a8a --- /dev/null +++ b/tests/cases/fourslash/goToImplementationTypeAlias_00.ts @@ -0,0 +1,12 @@ +/// + +// Should go to object literals within cast expressions when invoked on interface + +// @Filename: def.d.ts +//// export type TypeAlias = { P: number } + +// @Filename: ref.ts +//// import { TypeAlias } from "./def"; +//// const c: T/*ref*/ypeAlias = [|{ P: 2 }|]; + +verify.allRangesAppearInImplementationList("ref"); \ No newline at end of file