use getBaseTypeOfLiteralType

This commit is contained in:
Arthur Ozga 2017-02-15 14:24:25 -08:00
parent 18cba86e74
commit 9110461294
4 changed files with 21 additions and 4 deletions

View file

@ -83,7 +83,7 @@ namespace ts {
getSignaturesOfType,
getIndexTypeOfType,
getBaseTypes,
getWidenedType,
getBaseTypeOfLiteralType,
getTypeFromTypeNode,
getParameterType: getTypeAtPosition,
getReturnTypeOfSignature,

View file

@ -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.

View file

@ -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<number>(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 [{

View file

@ -78,6 +78,7 @@
"formatting/smartIndenter.ts",
"formatting/tokenRange.ts",
"codeFixProvider.ts",
"codefixes/fixAddMissingMember.ts",
"codefixes/fixExtendsInterfaceBecomesImplements.ts",
"codefixes/fixClassIncorrectlyImplementsInterface.ts",
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",