diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts
index 0a190e7b37..daa2166103 100644
--- a/src/services/codefixes/inferFromUsage.ts
+++ b/src/services/codefixes/inferFromUsage.ts
@@ -504,6 +504,9 @@ namespace ts.codefix {
}
switch (node.parent.kind) {
+ case SyntaxKind.ExpressionStatement:
+ addCandidateType(usage, checker.getVoidType());
+ break;
case SyntaxKind.PostfixUnaryExpression:
usage.isNumber = true;
break;
@@ -871,12 +874,11 @@ namespace ts.codefix {
}
if (usage.calls) {
- callSignatures.push(getSignatureFromCalls(usage.calls, checker.getVoidType()));
+ callSignatures.push(getSignatureFromCalls(usage.calls, checker.getAnyType()));
}
if (usage.constructs) {
- // TODO: fallback return should maybe be {}?
- constructSignatures.push(getSignatureFromCalls(usage.constructs, checker.getVoidType()));
+ constructSignatures.push(getSignatureFromCalls(usage.constructs, checker.getAnyType()));
}
if (usage.stringIndex) {
diff --git a/tests/cases/fourslash/codeFixInferFromCallInAssignment.ts b/tests/cases/fourslash/codeFixInferFromCallInAssignment.ts
new file mode 100644
index 0000000000..85e1d3bc50
--- /dev/null
+++ b/tests/cases/fourslash/codeFixInferFromCallInAssignment.ts
@@ -0,0 +1,9 @@
+///
+
+// @noImplicitAny: true
+//// function inferAny( [| app |] ) {
+//// const result = app.use('hi')
+//// return result
+//// }
+
+verify.rangeAfterCodeFix("app: { use: (arg0: string) => any; }");
diff --git a/tests/cases/fourslash/codeFixInferFromExpressionStatement.ts b/tests/cases/fourslash/codeFixInferFromExpressionStatement.ts
new file mode 100644
index 0000000000..b5969c7937
--- /dev/null
+++ b/tests/cases/fourslash/codeFixInferFromExpressionStatement.ts
@@ -0,0 +1,8 @@
+///
+
+// @noImplicitAny: true
+//// function inferVoid( [| app |] ) {
+//// app.use('hi')
+//// }
+
+verify.rangeAfterCodeFix("app: { use: (arg0: string) => void; }");
diff --git a/tests/cases/fourslash/codeFixInferFromUsageCommentAfterParameter.ts b/tests/cases/fourslash/codeFixInferFromUsageCommentAfterParameter.ts
index bdefd2b5de..866bfe04c1 100644
--- a/tests/cases/fourslash/codeFixInferFromUsageCommentAfterParameter.ts
+++ b/tests/cases/fourslash/codeFixInferFromUsageCommentAfterParameter.ts
@@ -16,7 +16,7 @@ verify.codeFix({
index: 0,
newFileContent:
`/**
- * @param {(arg0: any) => void} callback
+ * @param {(arg0: any) => any} callback
*/
function coll(callback /*, name1, name2, ... */) {
return callback(this);
diff --git a/tests/cases/fourslash/codeFixInferFromUsageJSXElement.ts b/tests/cases/fourslash/codeFixInferFromUsageJSXElement.ts
index 3200fffafb..abe35fe46c 100644
--- a/tests/cases/fourslash/codeFixInferFromUsageJSXElement.ts
+++ b/tests/cases/fourslash/codeFixInferFromUsageJSXElement.ts
@@ -30,4 +30,4 @@
//// }
-verify.rangeAfterCodeFix("props: { isLoading: any; update: (arg0: any) => void; }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0);
+verify.rangeAfterCodeFix("props: { isLoading: any; update: (arg0: any) => any; }",/*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 0);
diff --git a/tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts b/tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts
index c8b85ee11e..44d2e2d7b1 100644
--- a/tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts
+++ b/tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts
@@ -12,4 +12,4 @@
//// return x.y.z
////}
-verify.rangeAfterCodeFix("a: { b: { c: any; }; }, m: { n: () => number; }, x: { y: { z: number[]; }; }", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, /*index*/0);
\ No newline at end of file
+verify.rangeAfterCodeFix("a: { b: { c: void; }; }, m: { n: () => number; }, x: { y: { z: number[]; }; }", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, /*index*/0);
diff --git a/tests/cases/fourslash/codeFixInferFromUsagePropertyAccessJS.ts b/tests/cases/fourslash/codeFixInferFromUsagePropertyAccessJS.ts
index ed9d4b33b3..357b1a991b 100644
--- a/tests/cases/fourslash/codeFixInferFromUsagePropertyAccessJS.ts
+++ b/tests/cases/fourslash/codeFixInferFromUsagePropertyAccessJS.ts
@@ -21,7 +21,7 @@ verify.codeFix({
index: 0,
newFileContent:
`/**
- * @param {{ b: { c: any; }; }} a
+ * @param {{ b: { c: void; }; }} a
* @param {{ n: () => number; }} m
* @param {{ y: { z: number[]; }; }} x
*/