Microsoft/TypeScript

Interface Overload Generic Member - Compiler error when removing overload

Open

#51,370 创建于 2022年11月1日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: check: Type InferenceHelp Wanted

仓库指标

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

描述

Bug Report

Removing an overload member Controller.handle from Controller causes a compilation error.

🔎 Search Terms

  • Interface overload
  • Member Type Parameter
  • Works When Removing overload

⏯ Playground Link

Playground

💻 Code

Code below compiles

export interface Controller {
  handle<T>(httpRequest: HttpRequest<T>): HttpResponse<T>;
  handle<TRequest, TResponse>(httpRequest: HttpRequest<TRequest>): HttpResponse<TResponse>;
}

Code below does not compile

export interface Controller {
  // handle<T>(httpRequest: HttpRequest<T>): HttpResponse<T>;
  handle<TRequest, TResponse>(httpRequest: HttpRequest<TRequest>): HttpResponse<TResponse>;
}

Code below does not compile

export interface Controller {
  handle<T>(httpRequest: HttpRequest<T>): HttpResponse<T>;
  // handle<TRequest, TResponse>(httpRequest: HttpRequest<TRequest>): HttpResponse<TResponse>;
}

🙁 Actual behavior

Code does not compile when removing any of the overloads.

🙂 Expected behavior

Since having an overload in Controller.handle works, having just one member with the correct signature should also work.

Additional Info

贡献者指南