Skip to content

Commit 7c7e2aa

Browse files
Error on nodes which should not have type predicates.
1 parent cf13a71 commit 7c7e2aa

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11563,11 +11563,14 @@ namespace ts {
1156311563
return -1;
1156411564
}
1156511565

11566-
function checkTypePredicate(node: TypePredicateNode) {
11566+
function checkTypePredicate(node: TypePredicateNode): void {
1156711567
const parent = getTypePredicateParent(node);
1156811568
if (!parent) {
11569+
// The parent must not be valid.
11570+
error(node.parent, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
1156911571
return;
1157011572
}
11573+
1157111574
const typePredicate = getSignatureFromDeclaration(parent).typePredicate;
1157211575
if (!typePredicate) {
1157311576
return;

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,10 @@
723723
"category": "Error",
724724
"code": 1227
725725
},
726+
"A type predicate is only allowed in return type position for functions and methods.": {
727+
"category": "Error",
728+
"code": 1228
729+
},
726730
"A type predicate cannot reference a rest parameter.": {
727731
"category": "Error",
728732
"code": 1229

0 commit comments

Comments
 (0)