From e9841f3899ddba2052e5e68e68adfc9268afd891 Mon Sep 17 00:00:00 2001 From: "wenlu.wang" <805037171@163.com> Date: Wed, 8 Nov 2017 19:44:12 -0600 Subject: [PATCH] fix completions protected members in recursive generic types (#19192) (#19242) --- src/compiler/checker.ts | 7 +++---- ...ompletionsForRecursiveGenericTypesMember.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/completionsForRecursiveGenericTypesMember.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 38bc617c650..6f75bfa0d46 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15162,12 +15162,11 @@ namespace ts { if (flags & ModifierFlags.Static) { return true; } - // An instance property must be accessed through an instance of the enclosing class - if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) { + if (type.flags & TypeFlags.TypeParameter) { // get the original type -- represented as the type constraint of the 'this' type - type = getConstraintOfTypeParameter(type); + type = (type as TypeParameter).isThisType ? getConstraintOfTypeParameter(type) : getBaseConstraintOfType(type); } - if (!(getObjectFlags(getTargetType(type)) & ObjectFlags.ClassOrInterface && hasBaseType(type, enclosingClass))) { + if (!type || !hasBaseType(type, enclosingClass)) { error(errorNode, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass)); return false; } diff --git a/tests/cases/fourslash/completionsForRecursiveGenericTypesMember.ts b/tests/cases/fourslash/completionsForRecursiveGenericTypesMember.ts new file mode 100644 index 00000000000..993b9eb73ac --- /dev/null +++ b/tests/cases/fourslash/completionsForRecursiveGenericTypesMember.ts @@ -0,0 +1,18 @@ +/// + +//// export class TestBase> +//// { +//// public publicMethod(p: any): void {} +//// private privateMethod(p: any): void {} +//// protected protectedMethod(p: any): void {} +//// public test(t: T): void +//// { +//// t./**/ +//// } +//// } + +goTo.marker(); + +verify.completionListContains('publicMethod'); +verify.completionListContains('privateMethod'); +verify.completionListContains('protectedMethod');