A function should be context-sensitive if its return expression is (#17697)

* A function should be context-sensitive if its return expression is

* Remove outdated comment

* Fix typo
This commit is contained in:
Andy
2017-08-10 07:08:24 -07:00
committed by GitHub
parent 4c824505ad
commit fe3a05e89a
9 changed files with 75 additions and 28 deletions

View File

@@ -8405,16 +8405,17 @@ namespace ts {
if (forEach(node.parameters, p => !getEffectiveTypeAnnotationNode(p))) {
return true;
}
// For arrow functions we now know we're not context sensitive.
if (node.kind === SyntaxKind.ArrowFunction) {
return false;
if (node.kind !== SyntaxKind.ArrowFunction) {
// If the first parameter is not an explicit 'this' parameter, then the function has
// an implicit 'this' parameter which is subject to contextual typing.
const parameter = firstOrUndefined(node.parameters);
if (!(parameter && parameterIsThisKeyword(parameter))) {
return true;
}
}
// If the first parameter is not an explicit 'this' parameter, then the function has
// an implicit 'this' parameter which is subject to contextual typing. Otherwise we
// know that all parameters (including 'this') have type annotations and nothing is
// subject to contextual typing.
const parameter = firstOrUndefined(node.parameters);
return !(parameter && parameterIsThisKeyword(parameter));
// TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value.
return node.body.kind === SyntaxKind.Block ? false : isContextSensitive(node.body);
}
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {