Infer void from expr statement usage, not calls

This makes inferences a lot better.
This commit is contained in:
Nathan Shively-Sanders 2019-09-05 16:16:35 -07:00
parent ff38a1bc9b
commit 052a3d9d73
7 changed files with 26 additions and 7 deletions

View file

@ -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) {

View file

@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
// @noImplicitAny: true
//// function inferAny( [| app |] ) {
//// const result = app.use('hi')
//// return result
//// }
verify.rangeAfterCodeFix("app: { use: (arg0: string) => any; }");

View file

@ -0,0 +1,8 @@
/// <reference path='fourslash.ts' />
// @noImplicitAny: true
//// function inferVoid( [| app |] ) {
//// app.use('hi')
//// }
verify.rangeAfterCodeFix("app: { use: (arg0: string) => void; }");

View file

@ -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);

View file

@ -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);

View file

@ -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);
verify.rangeAfterCodeFix("a: { b: { c: void; }; }, m: { n: () => number; }, x: { y: { z: number[]; }; }", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, /*index*/0);

View file

@ -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
*/