Guys I have no idea what title to put for this question, but here is my problem: I'm trying to add typescript restrictions nested many levels deep for react components and contexts.
I've distilled my roadblock to this miniature code sample:
function simplified<T>(props: { generator: () => T, receiver: (t: T) => any }) {
}
function whatIWant<T>(props: { generator: (bob: any) => T, receiver: (t: T) => any }) {
}
function nonObject<T>(generator: (bob: any) => T, receiver: (t: T) => any) {
}
simplified({ generator: () => 123, receiver: (t) => console.log(t + 2) })
whatIWant({ generator: (bob) => bob ? 1 : 2, receiver: (t) => console.log(t + 2) })
nonObject((bob) => bob ? 1 : 2, (t) => console.log(t + 2))
The whatIWant function is showing an error because it thinks t is unknown type.
The other two (simplified and nonObject are correctly seeing t as a number type.
In the end, generator will be returning an object with several keys and types and I want those to be automatic. I do not want to add <> type params when invoking whatIWant. I've noticed they are not required for simplified. Any ideas?
I'm particularly confused by the difference between simplified and whatIWant
TypeScript 4.5.4
