From bfc1cbe34d9a345d042d474e73861a112621b57e Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Sun, 3 Mar 2019 00:02:38 +0200 Subject: [PATCH] Modified type checking to correctly infer literal types for method name and parameter index. --- src/compiler/checker.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7e6cb97a9302e..42c917234ebff 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20284,11 +20284,20 @@ namespace ts { // A parameter declaration decorator will have three arguments (see // `ParameterDecorator` in core.d.ts). const func = parent.parent; - return [ - createSyntheticExpression(expr, parent.parent.kind === SyntaxKind.Constructor ? getTypeOfSymbol(getSymbolOfNode(func)) : errorType), - createSyntheticExpression(expr, anyType), - createSyntheticExpression(expr, numberType) - ]; + if (func.kind === SyntaxKind.Constructor) { + return [ + createSyntheticExpression(expr, getTypeOfSymbol(getSymbolOfNode(func.parent))), + createSyntheticExpression(expr, undefinedType), + createSyntheticExpression(expr, getLiteralType(func.parameters.indexOf(parent))) + ]; + } + else { + return [ + createSyntheticExpression(expr, getParentTypeOfClassElement(func)), + createSyntheticExpression(expr, getClassElementPropertyKeyType(func)), + createSyntheticExpression(expr, getLiteralType(func.parameters.indexOf(parent))) + ]; + } case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: