Skip to content

Commit 880e2c0

Browse files
authored
support quickinfo and go-to-definition on typeof this (microsoft#47085)
* support quickinfo and go-to-definition on `typeof this` * update baseline * move code to checkIdentifier
1 parent 7cc0f75 commit 880e2c0

11 files changed

+536
-25
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25107,6 +25107,10 @@ namespace ts {
2510725107
}
2510825108

2510925109
function checkIdentifier(node: Identifier, checkMode: CheckMode | undefined): Type {
25110+
if (isThisInTypeQuery(node)) {
25111+
return checkThisExpression(node);
25112+
}
25113+
2511025114
const symbol = getResolvedSymbol(node);
2511125115
if (symbol === unknownSymbol) {
2511225116
return errorType;
@@ -41245,7 +41249,10 @@ namespace ts {
4124541249
case SyntaxKind.PrivateIdentifier:
4124641250
case SyntaxKind.PropertyAccessExpression:
4124741251
case SyntaxKind.QualifiedName:
41248-
return getSymbolOfNameOrPropertyAccessExpression(node as EntityName | PrivateIdentifier | PropertyAccessExpression);
41252+
if (!isThisInTypeQuery(node)) {
41253+
return getSymbolOfNameOrPropertyAccessExpression(node as EntityName | PrivateIdentifier | PropertyAccessExpression);
41254+
}
41255+
// falls through
4124941256

4125041257
case SyntaxKind.ThisKeyword:
4125141258
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);
@@ -143,7 +143,7 @@ namespace ts.SymbolDisplay {
143143
const symbolFlags = getCombinedLocalAndExportSymbolFlags(symbol);
144144
let symbolKind = semanticMeaning & SemanticMeaning.Value ? getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location) : ScriptElementKind.unknown;
145145
let hasAddedSymbolInfo = false;
146-
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isInExpressionContext(location);
146+
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isInExpressionContext(location) || isThisInTypeQuery(location);
147147
let type: Type | undefined;
148148
let printer: Printer;
149149
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)