Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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: 1 addition & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34547,9 +34547,7 @@ namespace ts {
: isBinaryExpression(location) && isIdentifier(location.right) ? location.right
: undefined;
const isPropertyExpressionCast = isPropertyAccessExpression(location)
&& isParenthesizedExpression(location.expression)
&& isAssertionExpression(location.expression.expression);

&& isAssertionExpression(skipParentheses(location.expression));
if (!testedNode || isPropertyExpressionCast) {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/truthinessCallExpressionCoercion3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ function f(result: unknown) {
return result
}
}
function g(result: unknown) {
if (((result as I)).always) {
return result
}
}


//// [truthinessCallExpressionCoercion3.js]
Expand All @@ -17,3 +22,8 @@ function f(result) {
return result;
}
}
function g(result) {
if (result.always) {
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ function f(result: unknown) {
>result : Symbol(result, Decl(truthinessCallExpressionCoercion3.ts, 5, 11))
}
}
function g(result: unknown) {
>g : Symbol(g, Decl(truthinessCallExpressionCoercion3.ts, 9, 1))
>result : Symbol(result, Decl(truthinessCallExpressionCoercion3.ts, 10, 11))

if (((result as I)).always) {
>((result as I)).always : Symbol(I.always, Decl(truthinessCallExpressionCoercion3.ts, 1, 13))
>result : Symbol(result, Decl(truthinessCallExpressionCoercion3.ts, 10, 11))
>I : Symbol(I, Decl(truthinessCallExpressionCoercion3.ts, 0, 0))
>always : Symbol(I.always, Decl(truthinessCallExpressionCoercion3.ts, 1, 13))

return result
>result : Symbol(result, Decl(truthinessCallExpressionCoercion3.ts, 10, 11))
}
}

16 changes: 16 additions & 0 deletions tests/baselines/reference/truthinessCallExpressionCoercion3.types
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@ function f(result: unknown) {
>result : unknown
}
}
function g(result: unknown) {
>g : (result: unknown) => unknown
>result : unknown

if (((result as I)).always) {
>((result as I)).always : () => void
>((result as I)) : I
>(result as I) : I
>result as I : I
>result : unknown
>always : () => void

return result
>result : unknown
}
}

5 changes: 5 additions & 0 deletions tests/cases/compiler/truthinessCallExpressionCoercion3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ function f(result: unknown) {
return result
}
}
function g(result: unknown) {
if (((result as I)).always) {
return result
}
}