Skip to content

Commit 8153475

Browse files
authored
fix(47438): show auto-complete for this inside class static blocks (microsoft#47460)
1 parent e2c0033 commit 8153475

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/services/completions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,8 +2086,7 @@ namespace ts.Completions {
20862086
// GH#39946. Pulling on the type of a node inside of a function with a contextual `this` parameter can result in a circularity
20872087
// if the `node` is part of the exprssion of a `yield` or `return`. This circularity doesn't exist at compile time because
20882088
// we will check (and cache) the type of `this` *before* checking the type of the node.
2089-
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
2090-
if (!isSourceFile(container) && container.parent) typeChecker.getTypeAtLocation(container);
2089+
typeChecker.tryGetThisTypeAt(node, /*includeGlobalThis*/ false);
20912090

20922091
let type = typeChecker.getTypeAtLocation(node).getNonOptionalType();
20932092
let insertQuestionDot = false;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @target: esnext
4+
////class Foo {
5+
//// static #a = 1;
6+
//// static a() {
7+
//// this./*1*/
8+
//// }
9+
//// static b() {
10+
//// Foo./*2*/
11+
//// }
12+
//// static {
13+
//// this./*3*/
14+
//// }
15+
//// static {
16+
//// Foo./*4*/
17+
//// }
18+
////}
19+
20+
verify.completions({
21+
marker: ["1", "2", "3", "4"],
22+
exact: completion.functionMembersPlus([
23+
{ name: "#a", sortText: completion.SortText.LocalDeclarationPriority },
24+
{ name: "a", sortText: completion.SortText.LocalDeclarationPriority },
25+
{ name: "b", sortText: completion.SortText.LocalDeclarationPriority },
26+
{ name: "prototype" }
27+
])
28+
});

0 commit comments

Comments
 (0)