Check 'infer' declarations are in extends clause of conditional type

This commit is contained in:
Anders Hejlsberg 2018-01-25 13:02:35 -08:00
parent ef0c3b7667
commit f59f3a2793
2 changed files with 13 additions and 0 deletions

View File

@ -20172,6 +20172,13 @@ namespace ts {
forEachChild(node, checkSourceElement);
}
function checkInferType(node: InferTypeNode) {
if (!findAncestor(node, n => n.parent && n.parent.kind === SyntaxKind.ConditionalType && (<ConditionalTypeNode>n.parent).extendsType === n)) {
grammarErrorOnNode(node, Diagnostics.infer_declarations_are_only_permitted_in_the_extends_clause_of_a_conditional_type);
}
checkSourceElement(node.typeParameter);
}
function isPrivateWithinAmbient(node: Node): boolean {
return hasModifier(node, ModifierFlags.Private) && !!(node.flags & NodeFlags.Ambient);
}
@ -23874,6 +23881,8 @@ namespace ts {
return checkTypeOperator(<TypeOperatorNode>node);
case SyntaxKind.ConditionalType:
return checkConditionalType(<ConditionalTypeNode>node);
case SyntaxKind.InferType:
return checkInferType(<InferTypeNode>node);
case SyntaxKind.JSDocAugmentsTag:
return checkJSDocAugmentsTag(node as JSDocAugmentsTag);
case SyntaxKind.JSDocTypedefTag:

View File

@ -947,6 +947,10 @@
"category": "Error",
"code": 1337
},
"'infer' declarations are only permitted in the 'extends' clause of a conditional type.": {
"category": "Error",
"code": 1338
},
"Duplicate identifier '{0}'.": {
"category": "Error",