Skip to content

Commit e9841f3

Browse files
Kingwlmhegazy
authored andcommitted
fix completions protected members in recursive generic types (#19192) (#19242)
1 parent 1408a4d commit e9841f3

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15162,12 +15162,11 @@ namespace ts {
1516215162
if (flags & ModifierFlags.Static) {
1516315163
return true;
1516415164
}
15165-
// An instance property must be accessed through an instance of the enclosing class
15166-
if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) {
15165+
if (type.flags & TypeFlags.TypeParameter) {
1516715166
// get the original type -- represented as the type constraint of the 'this' type
15168-
type = getConstraintOfTypeParameter(<TypeParameter>type);
15167+
type = (type as TypeParameter).isThisType ? getConstraintOfTypeParameter(<TypeParameter>type) : getBaseConstraintOfType(<TypeParameter>type);
1516915168
}
15170-
if (!(getObjectFlags(getTargetType(type)) & ObjectFlags.ClassOrInterface && hasBaseType(type, enclosingClass))) {
15169+
if (!type || !hasBaseType(type, enclosingClass)) {
1517115170
error(errorNode, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass));
1517215171
return false;
1517315172
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// export class TestBase<T extends TestBase<T>>
4+
//// {
5+
//// public publicMethod(p: any): void {}
6+
//// private privateMethod(p: any): void {}
7+
//// protected protectedMethod(p: any): void {}
8+
//// public test(t: T): void
9+
//// {
10+
//// t./**/
11+
//// }
12+
//// }
13+
14+
goTo.marker();
15+
16+
verify.completionListContains('publicMethod');
17+
verify.completionListContains('privateMethod');
18+
verify.completionListContains('protectedMethod');

0 commit comments

Comments
 (0)