Microsoft/TypeScript
GitHub ã§èŠãFunction argument is not infered correctly
Open
#62,336 opened on 2025幎8æ26æ¥
Domain: check: Type InferenceHelp WantedPossible Improvement
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
function, argument, parameter, generic, callback, infer
ð Version & Regression Information
By trying out different versions in Playground, it looks like it works correctly in version 4.7.4 and lower
⯠Playground Link
ð» Code
declare function call<T>(fn: (a: string, b: T) => unknown): (b: T) => unknown;
declare function fn<Args extends any[]>(
fn: (...args: Args) => unknown,
): (...args: Args) => unknown;
const result = call(fn(function (a, b: number) {}));
ð Actual behavior
The a parameter's type is any.
ð Expected behavior
The a paramater's type should be string
Additional information about the issue
I encountered this while trying to create a helper function in a codebase that uses Effect:
import { Effect } from "effect"
function call<A, E, R, T = void>(fn: (a: string, b: T) => Effect.Effect<A, E, R>) {
return (b: T) => fn("value", b)
}
const fnA = call((a, b: number) => // a is `string`
Effect.gen(function* () {
return yield* Effect.succeed(`${a}: ${b}`)
}),
)
const fnB = call(
Effect.fn(function* (a, b: number) { // a is `any`?
return yield* Effect.succeed(`${a}: ${b}`)
}),
)