I've encountered a problem regarding typescript and need some help
I'm new to typescript and a code block below illustrates shortened version of my problem.
interface A {
value1: string;
value2: string;
func(a: string, b: string): void;
}
interface B {
value1: number;
value2: number;
func(a: number, b: number): void;
}
function Outer <T extends A | B>(myFunc: T['func'], a: T['value1'], b: T['value2']) {
myFunc(a, b); // get an error: Argument of type 'string | number' is not assignable to parameter of type 'never'.
}
What I want is to pass parameters to 'Outer' function which will then infer 'T'.
I thought it would be okay to call 'myFunc', but error comes up and says I can't assign 'a' and 'b' to 'never'.
** This set of codes might look a bit weird. It's actually intended to be a react hook.
What's going on here? and What would be a proper way to solve this?
Thanks a lot in advance.