diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e146e809122..f28f82ed401 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2538,13 +2538,11 @@ namespace ts { } function parseTypeOrTypePredicate(): TypeNode { - const typePredicateVariable = tryParse(() => { - const id = parseIdentifier(); - if (token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { - nextToken(); - return id; - } - }); + let typePredicateVariable: Identifier; + if (isIdentifier()) { + typePredicateVariable = tryParse(parseTypePredicatePrefix); + } + const type = parseType(); if (typePredicateVariable) { const node = createNode(SyntaxKind.TypePredicate, typePredicateVariable.pos); @@ -2557,6 +2555,14 @@ namespace ts { } } + function parseTypePredicatePrefix() { + const id = parseIdentifier(); + if (token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { + nextToken(); + return id; + } + } + function parseType(): TypeNode { // The rules about 'yield' only apply to actual code/expression contexts. They don't // apply to 'type' contexts. So we disable these parameters here before moving on.