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

Contextual parameter types failed to be provided based on filtering mapped types #56881

Closed
Andarist opened this issue Dec 26, 2023 · 0 comments Β· Fixed by #56201
Closed

Contextual parameter types failed to be provided based on filtering mapped types #56881

Andarist opened this issue Dec 26, 2023 · 0 comments Β· Fixed by #56201
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

@Andarist
Copy link
Contributor

πŸ”Ž Search Terms

contextual parameter filtering mapped type inference generic

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.0-dev.20231226#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVIEYAeAFXhAA8MRVgBneHAIwCtwMA+ACgCh55gUDFABc8EgBo+8ABZRaEEDDpiA3vADaABXhZ8AaxABPHInHwoDLQF0xXAG5QIyEGJLbrE+AAcYOb2JaAJTwALwc8PY4WMDwAL5SQWJRMQDcPDyIBLz8qtL8iDg4YgAMUvz8TLBiAEQ15fENeRVIRXaOziBehkYh4fCqCfnwVTDtTi7dxn0Rgw1DQek8oJCwCCjo2HhIAEyk5FQ09Iys7NzSgsJuDXIKSioDmjp68D2m5pbiHgfUtAx0GBgegA5vAAPzwHRiVAgexKWzwBwTVxfGxeXz+QIzSLRWILZK4paIHY5AbDQrFeBlYajWr1aRDXI06qIjqTV7TMKzRmNHiLIA

πŸ’» Code

declare function f1<T extends object>(
  data: T,
  handlers: { [P in keyof T as P]: (value: T[P], prop: P) => void },
): void;

f1(
  {
    foo: 0,
    bar: "",
  },
  {
    foo: (value, key) => {},
    bar: (value, key) => {},
  },
);

declare function f2<T extends object>(
  data: T,
  handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void },
): void;

f2(
  {
    foo: 0,
    bar: "",
  },
  {
    bar: (value, key) => {},
  },
);

πŸ™ Actual behavior

All of those functions report:

Parameter 'value' implicitly has an 'any' type.(7006)

πŸ™‚ Expected behavior

I'd expect all of those parameters to be contextually typed without problems.

Additional information about the issue

No response

@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 Jan 2, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 2, 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
Development

Successfully merging a pull request may close this issue.

2 participants