Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An argument without a type confuses automatic type inference for a generic function #47242

Closed
oleg-slapdash opened this issue Dec 24, 2021 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@oleg-slapdash
Copy link

oleg-slapdash commented Dec 24, 2021

Bug Report

I am sorry for a dry bug report, I am not sure why it happens and what area of TS this is concerned but I have a repro in hopes this would be fixed.

🔎 Search Terms

No idea, really.

🕗 Version & Regression Information

  • This is the behavior in every version I tried.

⏯ Playground Link

Playground link with relevant code

💻 Code

export const data = {
  fails: castType({
    // NOTE: It fails if this function has an argument
    subscribe: (_foo) => ({ foo: "bar" } as const),
    resolve: (data) => data.foo,
  }),
  works: castType({
    // NOTE: It works if argument is not defined
    subscribe: () => ({ foo: "bar" } as const),
    resolve: (data) => data.foo,
  }),
};

export function castType<TPayload>(resolver: {
  subscribe: (foo: boolean) => TPayload;
  resolve?: (parent: TPayload) => any;
}) {
  return resolver;
}

🙁 Actual behavior

It fails to determine the correct type in a generic if an argument is specified.

🙂 Expected behavior

It should determine the correct types for a generic.

@MartinJohns
Copy link
Contributor

Duplicate of #43371.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants