I messed up the title, not sure the exact term for what I am trying to achieve. Type constraints are a bit confusing to me right now as I'm learning them in both F# and Typescript at the same time.
I have a variable called interface state that contains lists of all the necessary data types for the page
interface state{
clients: clients[]
appointments: appointments[]
...
}
const ApplicationState : state = {...}
I need a generic function that can retrieve a specific client, appointment, or any other data by its id.
For example:
getData('clients', 2)
To start, I defined a type with permitted properties (if there's a better way to do this, please let me know).
type entity = "clients" | "appointments"
But would it then be possible to access the property of ApplicationState
?
So, could the getData
function look something like this?
const getData = (foo: entity, id: number) => {
ApplicationState.magicallyGetPropertyByName.filter(entity => entity.id = foo.id)
}
Is it achievable while still maintaining type inference?
Appreciate your help