Visitar URL original
Argument type infer not work correctly without specify types of function params Β· Issue #47577 Β· microsoft/TypeScript Β· GitHub
The Wayback Machine - https://web.archive.org/web/20250628052557/https://github.com/microsoft/TypeScript/issues/47577
Skip to content

Argument type infer not work correctly without specify types of function paramsΒ #47577

Closed
@Jokcy

Description

@Jokcy

Bug Report

πŸ”Ž Search Terms

  • Argument type infer not work correctly

πŸ•— Version & Regression Information

seems to be every version of typescript shows this behavior

⏯ Playground Link

Playground Link

In this example, if you try the use commits in actions.a, you will see the type of commits is:

Record<string, (state: {
    name: string;
    arr: never[];
}, ...args: any) => void>

If I update the commit function to use state: State,

...
{
  commits: {
    a: (state: State, newName: string) => 'a'
  }
}
...

then the commits type in actions.a will be exactly what commits is, eg:

{
    a: (state: State, newName: string) => string;
}

πŸ™ Actual behavior

Without specify state: State, the commits type infer in actions.a not correct. I suppose TS will infer what state is, and there should not be different with/without specify state: State.

πŸ™‚ Expected behavior

there should not be different with/without specify state: State.

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