π Search Terms
correlated union signature union map mapped type index
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250508#code/C4TwDgpgBAIhBmBLAdo4iD2yDOUC8UA3gFBRRYBiGGAXFANoCGATgOZ3ICuAtgEYTMAugG5S5ZACEWdJmzrZgzFKxHEAvqOKhIUAMoZuEAMKMANqd6MAxgGtcBEmXoBpKCig2IIDPFgIUaJg4gnQAFAB0kSys2HRwSKjoWNguggCU+AB8UABuGIgAJqIaxMRWycBQAO7MjGAm5pa2+FAAPK4QAB7AEMgFuJ7evvqGDRbWdpmhYtgYnMxWEHQjxmbjttgANGLA0RDAywarjRNbYoN0ztsZeNmOUOU4lVZrTTYts-OL9IOqO3vAH5eQQtCJRNjYG53MRkRC+UIAWUYwAAFuFan0DKEMtkAAzhACsGXuZDIzH282QD1eEzB4WikNEpKgajEJRKxHgnGQViSVJqdQAguZQi8ThtDqMaRs0pLjus7EQxI8FNVamBIAUWoQ1FBGLgVmM3tgmVB4BhmFBQqZ9h4vG4qWKFZClcyBfVpTZRZ6tmq6prNnaQHqBl4fHojkbTmlTayyRTmPz1ZrisQgA
π» Code
type Definitions = {
onFoo: [arg: number];
onBar: [arg: string];
};
type SomeCallbacks = {
[K in keyof Definitions]: (...args: Definitions[K]) => void;
};
const wrapCallback = <K extends keyof SomeCallbacks>(
source: SomeCallbacks,
target: SomeCallbacks,
key: K,
) => {
const callback = source[key];
target[key] = (...args) => {
if (Math.random() > 0.5) {
return callback(...args);
}
};
};
function wrapAll(callbacks: SomeCallbacks): SomeCallbacks {
const wrapped = {} as SomeCallbacks;
for (let key in callbacks) {
wrapCallback(callbacks, wrapped, key as keyof SomeCallbacks);
}
return wrapped;
}
π Actual behavior
It fails to recognize that this function is assignable to target[key] despite the fact that args are contextually-typed by that target[key]
π Expected behavior
I'd expect this to typecheck just fine
Additional information about the issue
No response
π Search Terms
correlated union signature union map mapped type index
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250508#code/C4TwDgpgBAIhBmBLAdo4iD2yDOUC8UA3gFBRRYBiGGAXFANoCGATgOZ3ICuAtgEYTMAugG5S5ZACEWdJmzrZgzFKxHEAvqOKhIUAMoZuEAMKMANqd6MAxgGtcBEmXoBpKCig2IIDPFgIUaJg4gnQAFAB0kSys2HRwSKjoWNguggCU+AB8UABuGIgAJqIaxMRWycBQAO7MjGAm5pa2+FAAPK4QAB7AEMgFuJ7evvqGDRbWdpmhYtgYnMxWEHQjxmbjttgANGLA0RDAywarjRNbYoN0ztsZeNmOUOU4lVZrTTYts-OL9IOqO3vAH5eQQtCJRNjYG53MRkRC+UIAWUYwAAFuFan0DKEMtkAAzhACsGXuZDIzH282QD1eEzB4WikNEpKgajEJRKxHgnGQViSVJqdQAguZQi8ThtDqMaRs0pLjus7EQxI8FNVamBIAUWoQ1FBGLgVmM3tgmVB4BhmFBQqZ9h4vG4qWKFZClcyBfVpTZRZ6tmq6prNnaQHqBl4fHojkbTmlTayyRTmPz1ZrisQgA
π» Code
π Actual behavior
It fails to recognize that this function is assignable to
target[key]despite the fact thatargsare contextually-typed by thattarget[key]π Expected behavior
I'd expect this to typecheck just fine
Additional information about the issue
No response