Microsoft/TypeScript

Interface Overload Generic Member - Compiler error when removing overload

Aperta

#51.370 aperta il 1 nov 2022

 (5 commenti) (0 reazioni) (0 assegnatari)TypeScript (13.395 fork)batch import
BugDomain: check: Type InferenceHelp Wanted

Metriche repository

Star
 (108.860 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor