Skip to content

Commit 1ca41ee

Browse files
committed
Permit expando property function with return type annotation as assertion
1 parent 46b2c36 commit 1ca41ee

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/checker/flow.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,17 @@ func (c *Checker) getExplicitTypeOfSymbol(symbol *ast.Symbol, diagnostic *ast.Di
21602160
}
21612161

21622162
func (c *Checker) isDeclarationWithExplicitTypeAnnotation(node *ast.Node) bool {
2163-
return (ast.IsVariableDeclaration(node) || ast.IsPropertyDeclaration(node) || ast.IsPropertySignatureDeclaration(node) || ast.IsParameter(node)) && node.Type() != nil
2163+
return (ast.IsVariableDeclaration(node) || ast.IsPropertyDeclaration(node) || ast.IsPropertySignatureDeclaration(node) || ast.IsParameter(node)) && node.Type() != nil ||
2164+
c.isExpandoPropertyFunctionWithReturnTypeAnnotation(node)
2165+
}
2166+
2167+
func (c *Checker) isExpandoPropertyFunctionWithReturnTypeAnnotation(node *ast.Node) bool {
2168+
if ast.IsBinaryExpression(node) {
2169+
if expr := node.AsBinaryExpression().Right; ast.IsFunctionLike(expr) && expr.Type() != nil {
2170+
return true
2171+
}
2172+
}
2173+
return false
21642174
}
21652175

21662176
func (c *Checker) hasTypePredicateOrNeverReturnType(sig *Signature) bool {

0 commit comments

Comments
 (0)