Skip to content

Type check and Object key completion on overloaded functions with generic types defined in a class are incorrect #58226

Closed

Description

@MrKou47

🔎 Search Terms

generic overload class

I found an issue #53734 similar to the problem I had, but I am not quite sure if the root cause is the same. Therefore, I am opening this issue.

🕗 Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about Functions and Generics .

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.5#code/JYOwLgpgTgZghgYwgAgEJysg3gKGckOAWwgC5kBnMKUAcwG4cBfHAEwgQBsMUu4KKyAGIB7EdjzJOIuKwA8AFWQQAHpBCtB6KAG0AugD4AFJ2BVyVGiFr6AlOQAKUEUTMRFBxvmmzFytRAaWhjGhCQW1HT2yE4ubh6MkgD0ScgAkjDpyFAQAG7QYMhgABYoIvlQPqzI7DCgwGDAIiAANMgNlI2cnDUiEIIgIoUA7iJQANbI-P4ADhyQrAB0yalVfqrqmmghRmFknVa00bGuFO4KnitSMvJKG4Fb2vrGpuYHdHaOzqfnlyw4CGaVGQMDEyAAvAQIMNhGIjLYcDhQSJFmsnoYjDoAORYvS2ZApZAAYTGOQQhTAAE85sgEKUEOMkWJUTc5NpjDj8YS5ABaPk89IgQFQMkU6m8emTUo5RbIBSlZAzDDECCQTBUmkUYoiACunGqACMUKAYNActVpgADSx0S3IA06wpmZDWyLWfSW5Y4IA

💻 Code

interface Bar {
  name: string;
}
declare class Foo {
  load<T extends Bar[]>(list: string[]): Promise<T>;
  load<T extends Bar>(name: string): Promise<T>;

  // If I revert the overload definition, it still does not work as expected.
  // load<T extends Bar>(name: string): Promise<T>;
  // load<T extends Bar[]>(list: string[]): Promise<T>;
}

const foo = new Foo()

foo.load<Bar[]>(['']) // Correct type check
foo.load<Bar>('') // <---- Incorrect type check here. The parameter type should be inferred as `string` but is `string[]`.

🙁 Actual behavior

When overload function in class with generic type(One is an array and the other is a normal type), Typescript could not match the correct type.

I know that Typescript check the overloaded function from top-to-down, but it still not working even if i revert the definition.

🙂 Expected behavior

Should match the correct type in that case.

Additional information about the issue

No response

Activity

  1. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions