I am trying to work out whether there is way to have the keys of record by limited by the possible type value sit can take.
For example, I have a contraint: Record<string, unknown> property on my object, but there are a limited range of recognise values that can be used and their types correspond to a key:
type quantityConstraint = {
min: number
max: number
}
type availabilityConstraint = {
from: Date
to: Date
}
// with possible assigned data (each member is optional)
constraint: {
quantity: {
min: 1,
max: 2
},
availability: {
min: 1,
max: 2
}
}
I don't see any way of doing this with Record type, so I am wondering whether I am just missing something or wanting something that the language can't provide?
Edit: Looking at this, maybe going via an enum could work: https://www.typescriptlang.org/docs/handbook/enums.html
How TypeScript enums work