diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 32616d22648..31220ae89d9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -83,7 +83,7 @@ namespace ts { getSignaturesOfType, getIndexTypeOfType, getBaseTypes, - getWidenedType, + getBaseTypeOfLiteralType, getTypeFromTypeNode, getParameterType: getTypeAtPosition, getReturnTypeOfSignature, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1c5d6974edc..0a68f9af2ad 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2382,7 +2382,7 @@ getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; getIndexTypeOfType(type: Type, kind: IndexKind): Type; getBaseTypes(type: InterfaceType): BaseType[]; - getWidenedType(type: Type): Type; + getBaseTypeOfLiteralType(type: Type): Type; getReturnTypeOfSignature(signature: Signature): Type; /** * Gets the type of a parameter at a given position in a signature. diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 24fc6b16abb..fbb8b3a483b 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -30,6 +30,22 @@ namespace ts.codefix { // if function call, synthesize function declaration if(token.parent.parent.kind == SyntaxKind.CallExpression) { + const callExpression = token.parent.parent as CallExpression; + if(callExpression.typeArguments) { + /** + * We can't in general know which arguments should use the type of the expression + * or the type of the type argument in the declaration. Consider + * ``` + * class A { + * constructor(a: number){ + * this.foo(a,1,true); + * } + * } + * ``` + */ + return undefined; + } + } @@ -41,8 +57,8 @@ namespace ts.codefix { binaryExpression.operatorToken; const checker = context.program.getTypeChecker(); - const type = checker.getWidenedType(checker.getTypeAtLocation(binaryExpression.right)); - typeString = checker.typeToString(type); + const widenedType = checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(binaryExpression.right)); + typeString = checker.typeToString(widenedType); } return [{ diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index b4e8289f367..d88cf137afa 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -78,6 +78,7 @@ "formatting/smartIndenter.ts", "formatting/tokenRange.ts", "codeFixProvider.ts", + "codefixes/fixAddMissingMember.ts", "codefixes/fixExtendsInterfaceBecomesImplements.ts", "codefixes/fixClassIncorrectlyImplementsInterface.ts", "codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",