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

Function expression or method is not inferable when we have mapped type with a conditional type #60047

Open
dragomirtitian opened this issue Sep 24, 2024 · 2 comments Β· May be fixed by #56460
Open
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@dragomirtitian
Copy link
Contributor

πŸ”Ž Search Terms

conditional method arrow function

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

Playground Link

πŸ’» Code

type Map<T> =  { 
  readonly [P in keyof T]: T[P] extends boolean ? "boolean":  "other"
} 
export function buildCommand<F extends Record<string, unknown>>(builderArgs: { 
  func: (p: F) => void
  params: Map<NoInfer<F>>
}) {

}
type Foo = { foo: boolean };
// Function expression does not work
buildCommand({
  func: function (p: Foo) { },
  params: {
    foo: "boolean"
  }
})

// Methods don't work
buildCommand({
  func(p: Foo) { },
  params: {
    foo: "boolean"
  }
})

// Arrow function works
buildCommand({
  func: (p: Foo) => { },
  params: {
    foo: "boolean"
  }
})

πŸ™ Actual behavior

For the first two calls we get an error while the third one is successful

πŸ™‚ Expected behavior

All three calls should be successful

Additional information about the issue

Removing the constraint from F (Playground Link) or changing it to F extends Record<keyof F, unknown> (Playground Link) will remove the error.

@dragomirtitian
Copy link
Contributor Author

cc: @molisani

@Andarist
Copy link
Contributor

I happen to know a PR that fixes this: #56460

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Sep 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
3 participants