Microsoft/TypeScript

Function argument is not infered correctly

Open

#62,336 创建于 2025年8月26日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
Domain: check: Type InferenceHelp WantedPossible Improvement

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 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

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXzCgggB4AVAPgApFUAueKqBgZwxi1QHMAaeAIwZkAlPAC8FeGgDWqHAHdUwhlUHwR4yTLmKA3ACh9oSLAQp02PElQkAgjC4t4IAB4YQqYE6ioAngG0AXWp9eGsVADoo2EcGe0dRCSlUWQVUHn1lRiiImJY4hxZErRSdVAN9MDw2eDgWZAgMcQIiCBpUGjRMXHwmPjVUZABbfhAYUQBvAF9hYV0gA

💻 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}`)
  }),
)

贡献者指南