From f59f3a27936ff646a376ab6e8756ebdb910dabc8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 25 Jan 2018 13:02:35 -0800 Subject: [PATCH] Check 'infer' declarations are in extends clause of conditional type --- src/compiler/checker.ts | 9 +++++++++ src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0786aee366a..21fac5fe1e3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20172,6 +20172,13 @@ namespace ts { forEachChild(node, checkSourceElement); } + function checkInferType(node: InferTypeNode) { + if (!findAncestor(node, n => n.parent && n.parent.kind === SyntaxKind.ConditionalType && (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(node); case SyntaxKind.ConditionalType: return checkConditionalType(node); + case SyntaxKind.InferType: + return checkInferType(node); case SyntaxKind.JSDocAugmentsTag: return checkJSDocAugmentsTag(node as JSDocAugmentsTag); case SyntaxKind.JSDocTypedefTag: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6a14aab2aee..bac8bd818c9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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",