Skip to content

Commit

Permalink
use getBaseTypeOfLiteralType
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Ozga committed Feb 16, 2017
1 parent 150e2fb commit d9e0fff
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Expand Up @@ -83,7 +83,7 @@ namespace ts {
getSignaturesOfType,
getIndexTypeOfType,
getBaseTypes,
getWidenedType,
getBaseTypeOfLiteralType,
getTypeFromTypeNode,
getParameterType: getTypeAtPosition,
getReturnTypeOfSignature,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Expand Up @@ -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.
Expand Down
20 changes: 18 additions & 2 deletions src/services/codefixes/fixAddMissingMember.ts
Expand Up @@ -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;
}


}

Expand All @@ -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 [{
Expand Down
1 change: 1 addition & 0 deletions src/services/tsconfig.json
Expand Up @@ -78,6 +78,7 @@
"formatting/smartIndenter.ts",
"formatting/tokenRange.ts",
"codeFixProvider.ts",
"codefixes/fixAddMissingMember.ts",
"codefixes/fixExtendsInterfaceBecomesImplements.ts",
"codefixes/fixClassIncorrectlyImplementsInterface.ts",
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
Expand Down

0 comments on commit d9e0fff

Please sign in to comment.