I ran into what feels to be a limitation of type checking.
I Have the following code:
type CallbackState = "state1" | "state2";
type CallbackType<T> =
T extends "state1" ? { value: string } :
T extends "state2" ? boolean :
never;
function setIrrigationSequenceState<T extends CallbackState>(
state: T,
callback: (res: CallbackType<T>) => void
) {
if (state === "state1") {
callback({
value: "test",
});
}
}```
and I get the error `Argument of type '{ ok: true; value: null; }' is not assignable to parameter of type 'CallbackType<T>'.`
Theoretically typescript knows that T is type test, which would narrows 'CallbackType<T>' to (res: { value: string }) => void, for which the given value of `callback` is valid.
Is this just too much for the type system to handle?