Infer void from expr statement usage, not calls
This makes inferences a lot better.
This commit is contained in:
parent
ff38a1bc9b
commit
052a3d9d73
7 changed files with 26 additions and 7 deletions
|
@ -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) {
|
||||
|
|
|
@ -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; }");
|
|
@ -0,0 +1,8 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noImplicitAny: true
|
||||
//// function inferVoid( [| app |] ) {
|
||||
//// app.use('hi')
|
||||
//// }
|
||||
|
||||
verify.rangeAfterCodeFix("app: { use: (arg0: string) => void; }");
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue