In my code, I have created a simple IFactory<OUT>
interface along with two classes that implement it.
export interface IFactory<OUT = any> {
create(): OUT;
}
// number implementation
export class NumberFactory implements IFactory<number> { ... }
// string implementation
export class StringFactory implements IFactory<string> { ... }
In addition to this, there is a method called calculate()
which constructs an object based on the specified model.
Here is an example of a model:
const model: Record<string, IFactory> = {
num: new NumberFactory(),
str: new StringFactory()
}
After calling the calculate()
method, the result will look something like this:
const result = calculate(model);
/// result
/// {
/// num: 1,
/// str: "str"
/// }
The main question here is how we can determine the type of the result. I have attempted to use TypeScript utilities but haven't been successful so far.
Your assistance in solving this issue would be greatly appreciated. Thank you!