Skip to content

Commit 15b6c0c

Browse files
committed
Recursively scan function arguments
1 parent ef5f7bc commit 15b6c0c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16746,7 +16746,18 @@ namespace ts {
1674616746
function checkAndAggregateParameterExpressionTypes(parameter: ParameterDeclaration): Type[] {
1674716747
const func = <FunctionLikeDeclaration>parameter.parent;
1674816748
const usageTypes: Type[] = [];
16749-
forEachInvocation(<Block>func.body, invocation => {
16749+
const invocations: CallExpression[] = [];
16750+
16751+
function seekInvocations(f: FunctionBody) {
16752+
forEachInvocation(f, invocation => {
16753+
invocations.push(invocation);
16754+
invocation.arguments.filter(isFunctionExpressionOrArrowFunction).forEach(arg => seekInvocations(<Block>arg.body));
16755+
})
16756+
}
16757+
16758+
seekInvocations(<Block>func.body)
16759+
16760+
invocations.forEach(invocation => {
1675016761
const usages = invocation.arguments
1675116762
.map((arg, i) => ({ arg, symbol: getSymbolAtLocation(arg), i }))
1675216763
.filter(({ symbol }) => symbol && symbol.valueDeclaration === parameter);
@@ -16758,6 +16769,7 @@ namespace ts {
1675816769
const argumentTypes = usages.map(({ i }) => parameterTypes[i]).filter(t => !!t);
1675916770
usageTypes.splice(0, 0, ...argumentTypes);
1676016771
});
16772+
1676116773
return usageTypes.length ? usageTypes : undefined;
1676216774
}
1676316775

tests/cases/compiler/parameterInference.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ function f(x: number){
2222

2323
function g(x){ return f(x); };
2424
// => function g(x: number): number
25+
// CASE 4
26+
declare function f4(g: Function)
27+
function g4(x) {
28+
f4(() => {
29+
Math.sqrt(x)
30+
})
31+
}

0 commit comments

Comments
 (0)