I have an object merger inside of a class that currently works like this:
public merge(): TOne & TTwo {
return { ...this.objectOne, ...this.objectTwo };
}
I am trying to separate them because some properties may have the same name... My first idea was to create 2 variables whose names would be defined by a class property:
public merge(): { [this.objectOne.key]: TOne, [this.objectTwo.key]: TTwo } {
return { [this.objectOne.key]: { ...this.objectOne }, [this.objectTwo.key]: { ...this.objectTwo } };
}
But that does not work with generic types and shows this error:
A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol'
How can I merge them with a custom property name? Or any workaround? Or any suggestion?
PS.: I have just asked this question which I then realized would not be helpful to solve the actual problem.