Skip to content

Commit d9e0fff

Browse files
author
Arthur Ozga
committed
use getBaseTypeOfLiteralType
1 parent 150e2fb commit d9e0fff

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace ts {
8383
getSignaturesOfType,
8484
getIndexTypeOfType,
8585
getBaseTypes,
86-
getWidenedType,
86+
getBaseTypeOfLiteralType,
8787
getTypeFromTypeNode,
8888
getParameterType: getTypeAtPosition,
8989
getReturnTypeOfSignature,

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@
23822382
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
23832383
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
23842384
getBaseTypes(type: InterfaceType): BaseType[];
2385-
getWidenedType(type: Type): Type;
2385+
getBaseTypeOfLiteralType(type: Type): Type;
23862386
getReturnTypeOfSignature(signature: Signature): Type;
23872387
/**
23882388
* Gets the type of a parameter at a given position in a signature.

src/services/codefixes/fixAddMissingMember.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ namespace ts.codefix {
3030

3131
// if function call, synthesize function declaration
3232
if(token.parent.parent.kind == SyntaxKind.CallExpression) {
33+
const callExpression = token.parent.parent as CallExpression;
34+
if(callExpression.typeArguments) {
35+
/**
36+
* We can't in general know which arguments should use the type of the expression
37+
* or the type of the type argument in the declaration. Consider
38+
* ```
39+
* class A {
40+
* constructor(a: number){
41+
* this.foo<number>(a,1,true);
42+
* }
43+
* }
44+
* ```
45+
*/
46+
return undefined;
47+
}
48+
3349

3450
}
3551

@@ -41,8 +57,8 @@ namespace ts.codefix {
4157
binaryExpression.operatorToken;
4258

4359
const checker = context.program.getTypeChecker();
44-
const type = checker.getWidenedType(checker.getTypeAtLocation(binaryExpression.right));
45-
typeString = checker.typeToString(type);
60+
const widenedType = checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(binaryExpression.right));
61+
typeString = checker.typeToString(widenedType);
4662
}
4763

4864
return [{

src/services/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"formatting/smartIndenter.ts",
7979
"formatting/tokenRange.ts",
8080
"codeFixProvider.ts",
81+
"codefixes/fixAddMissingMember.ts",
8182
"codefixes/fixExtendsInterfaceBecomesImplements.ts",
8283
"codefixes/fixClassIncorrectlyImplementsInterface.ts",
8384
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",

0 commit comments

Comments
 (0)