Microsoft/TypeScript

Interface Overload Generic Member - Compiler error when removing overload

Open

#51,370 opened on 2022年11月1日

GitHub で見る
 (5 comments) (0 reactions) (0 assignees)TypeScript (6,726 forks)batch import
BugDomain: check: Type InferenceHelp Wanted

Repository metrics

Stars
 (48,455 stars)
PR merge metrics
 (平均マージ 6d 17h) (30d で 9 merged PRs)

説明

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

コントリビューターガイド