mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 10:29:01 -06:00
fix(41827): allow infer parameters from method signature usage (#41836)
This commit is contained in:
parent
71e881a7ee
commit
0fa41db6c6
@ -453,6 +453,7 @@ namespace ts.codefix {
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
searchToken = containingFunction.name;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface Options {
|
||||
//// run(a, b, c, d, e, f): void;
|
||||
////}
|
||||
////
|
||||
////interface I {
|
||||
//// x: number;
|
||||
////}
|
||||
////
|
||||
////enum E {
|
||||
//// X
|
||||
////}
|
||||
////
|
||||
////function foo(options: Options) {
|
||||
//// const a = 1;
|
||||
//// const b = "";
|
||||
//// const c = { x: 1, y: 1 };
|
||||
//// const d = [1, 2, 3];
|
||||
//// const e: I = { x: 1 };
|
||||
//// const f: E = E.X;
|
||||
////
|
||||
//// options.run(a, b, c, d, e, f);
|
||||
////}
|
||||
|
||||
verify.codeFixAll({
|
||||
fixId: "inferFromUsage",
|
||||
fixAllDescription: "Infer all types from usage",
|
||||
newFileContent:
|
||||
`interface Options {
|
||||
run(a: number, b: string, c: { x: number; y: number; }, d: number[], e: I, f: E): void;
|
||||
}
|
||||
|
||||
interface I {
|
||||
x: number;
|
||||
}
|
||||
|
||||
enum E {
|
||||
X
|
||||
}
|
||||
|
||||
function foo(options: Options) {
|
||||
const a = 1;
|
||||
const b = "";
|
||||
const c = { x: 1, y: 1 };
|
||||
const d = [1, 2, 3];
|
||||
const e: I = { x: 1 };
|
||||
const f: E = E.X;
|
||||
|
||||
options.run(a, b, c, d, e, f);
|
||||
}`,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user