Currently, I have a function with one generic parameter and two function parameters. When utilizing "String Literal Type," the two function parameters can have different values:
function func2<T extends 'A' | 'B'>(x: T, y: T): void { }
func2('A', 'A'); // OK
func2('A', 'B'); // OK, why?
func2('A', 'C'); // ERR
However, I require that both x
and y
to be the same, similar to the example shown with classes:
class A { public a;}
class B { public b;}
class C { public c;}
function func1<T extends A | B>(x: T, y: T): void { }
func1(new A(), new A()); // OK
func1(new A(), new B()); // ERR
func1(new A(), new C()); // ERR
I am exploring if there is a feasible way for x
and y
to have matching values using "String Literal Type."