Skip to content

Commit 5edf726

Browse files
committed
Revert to declared type when '!' postfix operator would produce 'nothing'
1 parent 8c9348d commit 5edf726

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7621,6 +7621,9 @@ namespace ts {
76217621
const visitedFlowStart = visitedFlowCount;
76227622
const result = getTypeAtFlowNode(reference.flowNode);
76237623
visitedFlowCount = visitedFlowStart;
7624+
if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull) === nothingType) {
7625+
return declaredType;
7626+
}
76247627
return result;
76257628

76267629
function getTypeAtFlowNode(flow: FlowNode): Type {

0 commit comments

Comments
 (0)