Skip to content
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
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31843,7 +31843,9 @@ namespace ts {
let childExpression = childNode.parent;
while (testedExpression && childExpression) {

if (isIdentifier(testedExpression) && isIdentifier(childExpression)) {
if (isIdentifier(testedExpression) && isIdentifier(childExpression) ||
testedExpression.kind === SyntaxKind.ThisKeyword && childExpression.kind === SyntaxKind.ThisKeyword
) {
return getSymbolAtLocation(testedExpression) === getSymbolAtLocation(childExpression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ tests/cases/compiler/truthinessCallExpressionCoercion1.ts(61,9): error TS2774: T

// ok
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;

// ok
if (this.isUser) {
this.isUser();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class Foo {

// ok
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;

// ok
if (this.isUser) {
this.isUser();
}
}
}

Expand Down Expand Up @@ -117,6 +122,10 @@ var Foo = /** @class */ (function () {
this.isUser ? console.log('this.isUser') : undefined;
// ok
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
// ok
if (this.isUser) {
this.isUser();
}
};
return Foo;
}());
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ class Foo {
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)

// ok
if (this.isUser) {
>this.isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 52, 32))
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 49, 1))
>isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 52, 32))

this.isUser();
>this.isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 52, 32))
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 49, 1))
>isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 52, 32))
}
}
}

13 changes: 13 additions & 0 deletions tests/baselines/reference/truthinessCallExpressionCoercion1.types
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ class Foo {
>log : (...data: any[]) => void
>'this.maybeIsUser' : "this.maybeIsUser"
>undefined : undefined

// ok
if (this.isUser) {
>this.isUser : () => boolean
>this : this
>isUser : () => boolean

this.isUser();
>this.isUser() : boolean
>this.isUser : () => boolean
>this : this
>isUser : () => boolean
}
}
}

5 changes: 5 additions & 0 deletions tests/cases/compiler/truthinessCallExpressionCoercion1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ class Foo {

// ok
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;

// ok
if (this.isUser) {
this.isUser();
}
}
}