Consider this scenario: I have created a set of interfaces that define the entities within my system:
interface Company {
name: string
}
interface Employee {
firstName: string
lastName: string
}
Now, what I am looking for is a universal function that can retrieve these entities based on the interface specified as a string.
const company = findOne('Company', 1)
const employee = findOne('Employee', 2)
My question is, is it feasible to introduce a dynamic return type in the findOne
function? This way, when we use it like shown above, the compiler recognizes company
and employee
as instances of Company
and Employee
respectively?