Skip to content

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

@Andarist

Description

@Andarist

🔎 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions