Skip to content

Commit 4ec5509

Browse files
committed
support quickinfo and go-to-definition on typeof this
1 parent e2c89af commit 4ec5509

11 files changed

+532
-28
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34018,7 +34018,7 @@ namespace ts {
3401834018
}
3401934019
switch (kind) {
3402034020
case SyntaxKind.Identifier:
34021-
return checkIdentifier(node as Identifier, checkMode);
34021+
return isThisInTypeQuery(node) ? checkThisExpression(node) : checkIdentifier(node as Identifier, checkMode);
3402234022
case SyntaxKind.PrivateIdentifier:
3402334023
return checkPrivateIdentifierExpression(node as PrivateIdentifier);
3402434024
case SyntaxKind.ThisKeyword:
@@ -41072,7 +41072,10 @@ namespace ts {
4107241072
case SyntaxKind.PrivateIdentifier:
4107341073
case SyntaxKind.PropertyAccessExpression:
4107441074
case SyntaxKind.QualifiedName:
41075-
return getSymbolOfNameOrPropertyAccessExpression(node as EntityName | PrivateIdentifier | PropertyAccessExpression);
41075+
if (!isThisInTypeQuery(node)) {
41076+
return getSymbolOfNameOrPropertyAccessExpression(node as EntityName | PrivateIdentifier | PropertyAccessExpression);
41077+
}
41078+
// falls through
4107641079

4107741080
case SyntaxKind.ThisKeyword:
4107841081
const container = getThisContainer(node, /*includeArrowFunctions*/ false);

src/services/symbolDisplay.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace ts.SymbolDisplay {
4141
if (typeChecker.isArgumentsSymbol(symbol)) {
4242
return ScriptElementKind.localVariableElement;
4343
}
44-
if (location.kind === SyntaxKind.ThisKeyword && isExpression(location)) {
44+
if (location.kind === SyntaxKind.ThisKeyword && isExpression(location) || isThisInTypeQuery(location)) {
4545
return ScriptElementKind.parameterElement;
4646
}
4747
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
@@ -151,7 +151,7 @@ namespace ts.SymbolDisplay {
151151
const symbolFlags = getCombinedLocalAndExportSymbolFlags(symbol);
152152
let symbolKind = semanticMeaning & SemanticMeaning.Value ? getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location) : ScriptElementKind.unknown;
153153
let hasAddedSymbolInfo = false;
154-
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isInExpressionContext(location);
154+
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isInExpressionContext(location) || isThisInTypeQuery(location);
155155
let type: Type | undefined;
156156
let printer: Printer;
157157
let documentationFromAlias: SymbolDisplayPart[] | undefined;

tests/baselines/reference/initializerReferencingConstructorLocals.symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class C {
1616

1717
d: typeof this.z; // error
1818
>d : Symbol(C.d, Decl(initializerReferencingConstructorLocals.ts, 5, 15))
19+
>this : Symbol(C, Decl(initializerReferencingConstructorLocals.ts, 0, 0))
1920

2021
constructor(x) {
2122
>x : Symbol(x, Decl(initializerReferencingConstructorLocals.ts, 7, 16))
@@ -40,6 +41,7 @@ class D<T> {
4041

4142
d: typeof this.z; // error
4243
>d : Symbol(D.d, Decl(initializerReferencingConstructorLocals.ts, 15, 15))
44+
>this : Symbol(D, Decl(initializerReferencingConstructorLocals.ts, 10, 1))
4345

4446
constructor(x: T) {
4547
>x : Symbol(x, Decl(initializerReferencingConstructorLocals.ts, 17, 16))

tests/baselines/reference/initializerReferencingConstructorLocals.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class C {
2121
d: typeof this.z; // error
2222
>d : any
2323
>this.z : any
24-
>this : any
24+
>this : this
2525
>z : any
2626

2727
constructor(x) {
@@ -54,7 +54,7 @@ class D<T> {
5454
d: typeof this.z; // error
5555
>d : any
5656
>this.z : any
57-
>this : any
57+
>this : this
5858
>z : any
5959

6060
constructor(x: T) {

tests/baselines/reference/initializerReferencingConstructorParameters.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class E {
3939
b: typeof this.x; // ok
4040
>b : Symbol(E.b, Decl(initializerReferencingConstructorParameters.ts, 15, 15))
4141
>this.x : Symbol(E.x, Decl(initializerReferencingConstructorParameters.ts, 17, 16))
42+
>this : Symbol(E, Decl(initializerReferencingConstructorParameters.ts, 12, 1))
4243
>x : Symbol(E.x, Decl(initializerReferencingConstructorParameters.ts, 17, 16))
4344

4445
constructor(public x) { }

tests/baselines/reference/initializerReferencingConstructorParameters.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class E {
4343
b: typeof this.x; // ok
4444
>b : any
4545
>this.x : any
46-
>this : any
46+
>this : this
4747
>x : any
4848

4949
constructor(public x) { }

0 commit comments

Comments
 (0)