Skip to content

Implicit generics inference with nested types Β #47230

Closed

Description

Bug Report

πŸ”Ž Search Terms

Generics, Implicit Generics, Generics Inference

πŸ•— Version & Regression Information

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

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Command = (...args: Array<any>) => any;

type Client<C extends Command> = {
  command: C;
};

type ClientOptions<C extends Command> = {
  command: C;
}

type Setup<C extends Command> = (client: Client<C>) => unknown;

function test1<C extends Command>(
  setup: Setup<C>,
  options: ClientOptions<C>
): void {}

test1(async client => {
  // `client.command` type is `Command`, but should be inferred from `options.command`
  client.command('message');
  //     ^?
}, {
  command(message: string): void {
    console.log(message);
  }
});

function test2<C extends Command>(
  setup: Setup<C>,
  command: C
): void {}

test2(async client => {
  // works as expected, "client.command" type is inferred from `command` (the next argument)
  client.command('message');
  //     ^?
}, (message: string): void => {
  console.log(message);
});

πŸ™ Actual behavior

test1 - client.command type is Command
test2 - works as expected

πŸ™‚ Expected behavior

test1 - client.command type should be (message: string) => void

Activity

  1. leibale commented on Dec 27, 2021

    @leibale
    Author
  2. RyanCavanaugh commented on Jan 5, 2022

    @RyanCavanaugh
    Member

    Duplicate #38623

  3. 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

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions