-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Help WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
π Search Terms
contextual parameter filtering mapped type inference generic
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» 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
Labels
Help WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases