Microsoft/TypeScript
GitHub ã§èŠãNested generic calls don't inherit outer inferences when their return types are intersections containing functions
Open
#58,833 opened on 2024幎6æ12æ¥
Domain: IntersectionHelp WantedPossible Improvement
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
generic call inference intersection return type
ð Version & Regression Information
- This is the behavior in every version I tried
⯠Playground Link
ð» Code
interface Config<T> {
context: T;
invoke: {
(x: T): void;
exec: (x: T) => void;
};
}
declare function create<T>(config: Config<T>): void;
declare function myInvokeBroken<T>(i: { exec: (x: T) => void }): {
(x: T): void;
} & typeof i;
create({
context: { count: 3 },
invoke: myInvokeBroken({
exec: (x) => {
x
// ^?
x.count.toFixed(2);
},
}),
});
declare function myInvoke<T>(i: { exec: (x: T) => void }): {
(x: T): void;
exec: (x: T) => void;
};
create({
context: { count: 3 },
invoke: myInvoke({
exec: (x) => {
x
// ^?
x.count.toFixed(2);
},
}),
});
ð Actual behavior
x doesn't get contextually typed based on the outer inferences in the myInvokeBroken example
ð Expected behavior
I would expect myInvokeBroken and myInvoke to work here in the same way. Their return types are the same. It's only that myInvokeBroken is using an intersection in its return type while myInvoke isn't
Additional information about the issue
No response