Revert to declared type when '!' postfix operator would produce 'nothing'

This commit is contained in:
Anders Hejlsberg 2016-05-11 09:26:03 -07:00
parent 8c9348d8d6
commit 5edf72666d

View file

@ -7621,6 +7621,9 @@ namespace ts {
const visitedFlowStart = visitedFlowCount;
const result = getTypeAtFlowNode(reference.flowNode);
visitedFlowCount = visitedFlowStart;
if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull) === nothingType) {
return declaredType;
}
return result;
function getTypeAtFlowNode(flow: FlowNode): Type {