Skip to content

Commit 752e0ba

Browse files
committed
Fixes type predicate crash bug
1 parent 6db4faf commit 752e0ba

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5761,6 +5761,7 @@ namespace ts {
57615761
let signature = getResolvedSignature(expr);
57625762

57635763
if (signature.typePredicate &&
5764+
expr.arguments[signature.typePredicate.parameterIndex] &&
57645765
getSymbolAtLocation(expr.arguments[signature.typePredicate.parameterIndex]) === symbol) {
57655766

57665767
if (!assumeTrue) {

tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function hasMissingIsKeyword(): x {
2323
return true;
2424
}
2525

26+
function hasMissingParameter(): x is A {
27+
return true;
28+
}
29+
2630
function hasMissingTypeInTypeGuardType(x): x is {
2731
return true;
2832
}
@@ -132,4 +136,10 @@ function b6([a, b, p1], p2, p3): p1 is A {
132136

133137
function b7({a, b, c: {p1}}, p2, p3): p1 is A {
134138
return true;
139+
}
140+
141+
// Should not crash the compiler
142+
var x: A;
143+
if (hasMissingParameter()) {
144+
x.propA;
135145
}

0 commit comments

Comments
 (0)