Use custom type guard.

This commit is contained in:
Daniel Rosenwasser
2015-09-18 10:58:17 -07:00
parent 76da69c6c6
commit 2aa97bd1b9
2 changed files with 5 additions and 5 deletions

View File

@@ -6907,7 +6907,7 @@ namespace ts {
}
}
function isFunctionExpressionOrArrowFunction(node: Node): boolean {
function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression {
return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction;
}
@@ -6926,8 +6926,8 @@ namespace ts {
function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature {
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
let type = isObjectLiteralMethod(node)
? getContextualTypeForObjectLiteralMethod(<MethodDeclaration>node)
: getContextualType(<FunctionExpression>node);
? getContextualTypeForObjectLiteralMethod(node)
: getContextualType(node);
if (!type) {
return undefined;
}
@@ -13656,7 +13656,7 @@ namespace ts {
forEach(node.decorators, checkFunctionAndClassExpressionBodies);
forEach((<MethodDeclaration>node).parameters, checkFunctionAndClassExpressionBodies);
if (isObjectLiteralMethod(node)) {
checkFunctionExpressionOrObjectLiteralMethodBody(<MethodDeclaration>node);
checkFunctionExpressionOrObjectLiteralMethodBody(node);
}
break;
case SyntaxKind.Constructor:

View File

@@ -660,7 +660,7 @@ namespace ts {
return node && node.kind === SyntaxKind.Block && isFunctionLike(node.parent);
}
export function isObjectLiteralMethod(node: Node) {
export function isObjectLiteralMethod(node: Node): node is MethodDeclaration {
return node && node.kind === SyntaxKind.MethodDeclaration && node.parent.kind === SyntaxKind.ObjectLiteralExpression;
}