* Fix #19257: Ensure a generated signature has a return type * Ensure generated properties have types * Use the same context for multiple inferences to the same property access
This commit is contained in:
parent
2cc4f537af
commit
0c1730a218
3 changed files with 26 additions and 3 deletions
|
@ -521,7 +521,7 @@ namespace ts.codefix {
|
|||
if (!usageContext.properties) {
|
||||
usageContext.properties = createUnderscoreEscapedMap<UsageContext>();
|
||||
}
|
||||
const propertyUsageContext = {};
|
||||
const propertyUsageContext = usageContext.properties.get(name) || { };
|
||||
inferTypeFromContext(parent, checker, propertyUsageContext);
|
||||
usageContext.properties.set(name, propertyUsageContext);
|
||||
}
|
||||
|
@ -575,7 +575,7 @@ namespace ts.codefix {
|
|||
if (usageContext.properties) {
|
||||
usageContext.properties.forEach((context, name) => {
|
||||
const symbol = checker.createSymbol(SymbolFlags.Property, name);
|
||||
symbol.type = getTypeFromUsageContext(context, checker);
|
||||
symbol.type = getTypeFromUsageContext(context, checker) || checker.getAnyType();
|
||||
members.set(name, symbol);
|
||||
});
|
||||
}
|
||||
|
@ -636,7 +636,7 @@ namespace ts.codefix {
|
|||
symbol.type = checker.getWidenedType(checker.getBaseTypeOfLiteralType(callContext.argumentTypes[i]));
|
||||
parameters.push(symbol);
|
||||
}
|
||||
const returnType = getTypeFromUsageContext(callContext.returnType, checker);
|
||||
const returnType = getTypeFromUsageContext(callContext.returnType, checker) || checker.getVoidType();
|
||||
return checker.createSignature(/*declaration*/ undefined, /*typeParameters*/ undefined, /*thisParameter*/ undefined, parameters, returnType, /*typePredicate*/ undefined, callContext.argumentTypes.length, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
|
||||
}
|
||||
|
||||
|
|
8
tests/cases/fourslash/codeFixInferFromUsageCall.ts
Normal file
8
tests/cases/fourslash/codeFixInferFromUsageCall.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noImplicitAny: true
|
||||
////function wat([|b |]) {
|
||||
//// b();
|
||||
////}
|
||||
|
||||
verify.rangeAfterCodeFix("b: () => void");
|
15
tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts
Normal file
15
tests/cases/fourslash/codeFixInferFromUsagePropertyAccess.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noImplicitAny: true
|
||||
////function foo([|a, m, x |]) {
|
||||
//// a.b.c;
|
||||
////
|
||||
//// var numeric = 0;
|
||||
//// numeric = m.n();
|
||||
////
|
||||
//// x.y.z
|
||||
//// x.y.z.push(0);
|
||||
//// return x.y.z
|
||||
////}
|
||||
|
||||
verify.rangeAfterCodeFix("a: { b: { c: any; }; }, m: { n: () => number; }, x: { y: { z: number[]; }; }", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, /*index*/0);
|
Loading…
Reference in a new issue