Extra generic for b
should help:
const myFn = <T,>(p: {
a: (n: number) => T,
b: <U extends T /* EXTRA U generic */>(o: U) => void,
}) => {
// ...
}
myFn({
a: () => ({ n: 0 }), // Parameter of a is ignored
b: o => { o.n }, // Works!
})
myFn({
a: i => ({ n: 0 }), // Parameter i is used
b: o => { o.n }, // Works
})
This article should help to understand why your approach did not work
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…