Skip to content

support quickinfo and go-to-definition on typeof this #47085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24993,6 +24993,10 @@ namespace ts {
}

function checkIdentifier(node: Identifier, checkMode: CheckMode | undefined): Type {
if (isThisInTypeQuery(node)) {
return checkThisExpression(node);
}

const symbol = getResolvedSymbol(node);
if (symbol === unknownSymbol) {
return errorType;
Expand Down Expand Up @@ -41072,7 +41076,10 @@ namespace ts {
case SyntaxKind.PrivateIdentifier:
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.QualifiedName:
return getSymbolOfNameOrPropertyAccessExpression(node as EntityName | PrivateIdentifier | PropertyAccessExpression);
if (!isThisInTypeQuery(node)) {
return getSymbolOfNameOrPropertyAccessExpression(node as EntityName | PrivateIdentifier | PropertyAccessExpression);
}
// falls through

case SyntaxKind.ThisKeyword:
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
Expand Down
4 changes: 2 additions & 2 deletions src/services/symbolDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace ts.SymbolDisplay {
if (typeChecker.isArgumentsSymbol(symbol)) {
return ScriptElementKind.localVariableElement;
}
if (location.kind === SyntaxKind.ThisKeyword && isExpression(location)) {
if (location.kind === SyntaxKind.ThisKeyword && isExpression(location) || isThisInTypeQuery(location)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably out of scope for this review, but it would be nice for these two checks to use the same code (not isExpression vs isExpressionContext), and then be extracted to a function.

return ScriptElementKind.parameterElement;
}
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
Expand Down Expand Up @@ -151,7 +151,7 @@ namespace ts.SymbolDisplay {
const symbolFlags = getCombinedLocalAndExportSymbolFlags(symbol);
let symbolKind = semanticMeaning & SemanticMeaning.Value ? getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location) : ScriptElementKind.unknown;
let hasAddedSymbolInfo = false;
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isInExpressionContext(location);
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isInExpressionContext(location) || isThisInTypeQuery(location);
let type: Type | undefined;
let printer: Printer;
let documentationFromAlias: SymbolDisplayPart[] | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class C {

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

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

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

constructor(x: T) {
>x : Symbol(x, Decl(initializerReferencingConstructorLocals.ts, 17, 16))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class C {
d: typeof this.z; // error
>d : any
>this.z : any
>this : any
>this : this
>z : any

constructor(x) {
Expand Down Expand Up @@ -54,7 +54,7 @@ class D<T> {
d: typeof this.z; // error
>d : any
>this.z : any
>this : any
>this : this
>z : any

constructor(x: T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class E {
b: typeof this.x; // ok
>b : Symbol(E.b, Decl(initializerReferencingConstructorParameters.ts, 15, 15))
>this.x : Symbol(E.x, Decl(initializerReferencingConstructorParameters.ts, 17, 16))
>this : Symbol(E, Decl(initializerReferencingConstructorParameters.ts, 12, 1))
>x : Symbol(E.x, Decl(initializerReferencingConstructorParameters.ts, 17, 16))

constructor(public x) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class E {
b: typeof this.x; // ok
>b : any
>this.x : any
>this : any
>this : this
>x : any

constructor(public x) { }
Expand Down
Loading